Difference: 1. The hash route has "#" on the URL in the address bar, but the history route does not; 2. When performing a press enter refresh operation, the hash route will be loaded into the page corresponding to the address bar, while the history route Generally, a 404 error will occur; 3. Hash supports some lower version browsers, but history does not support it.
The operating environment of this article: Windows 10 system, Vue version 2.9.6, DELL G3 computer.
What is the difference between history and hash in vue
1. The hash route has # on the address bar URL and is read with window.location.hash. The history route will not look better.
2. We perform a press enter refresh operation, and the hash route will be loaded to the page corresponding to the address bar, while the history route usually reports a 404 error (refresh is Network request, an error will be reported if there is no backend preparation).
3. Hash routing supports lower version browsers, while history routing is a new API in HTML5.
4.hash is characterized by that although it appears in the URL, it is not included in the http request, so it has no impact on the backend, so changing the hash will not re- Load the page, so this is also a must for single-page applications.
5.history uses the browser's history stack. There were back, forward, and go methods before. Later, pushState() and replaceState() methods were added in HTML5. They Provides the function of modifying the history record. However, when modifying, although the current URL is changed, the browser will not immediately send a request to the backend.
6. This mode of history requires background configuration support. For example: when we go to the homepage of the project, everything is normal and can be accessed, but when we refresh the page or directly access the path, 404 will be returned. That is because in history mode, window.history is only dynamically operated through js. To change the path in the browser address bar, no http request is initiated, but when I enter this address directly in the browser, I must initiate an http request to the server, but this target does not exist on the server, so Will return 404
Summary
Of course, history is not good for everything. Although SPA works well in the browser, the difference between the two comes when you really need to initiate an HTTP request to the backend through the URL. Especially when the user manually enters the URL and presses Enter, or refreshes (restarts) the browser.
1: In hash mode, only the content before the hash symbol will be included in the request, such as http://www.abc.com, so for the backend, even if the routing is not implemented Full coverage, no 404 error will be returned.
2: In history mode, the URL of the front-end must be consistent with the URL that actually initiates the request to the back-end. Such as http://www.abc.com/book/id. If the backend lacks routing processing for /book/id, a 404 error will be returned
Problem solution:
Solutions to 404 errors: Many methods introduced online will not work. Install the URL rewriting module, configure the rewriting rules, and point them to index.html. Or directly place the web.config file generated by URL rewriting directly in the root directory of the website.
【Related recommendation: "vue.js Tutorial"】
The above is the detailed content of What is the difference between history and hash in vue. For more information, please follow other related articles on the PHP Chinese website!

Vue.js and React each have their own advantages in scalability and maintainability. 1) Vue.js is easy to use and is suitable for small projects. The Composition API improves the maintainability of large projects. 2) React is suitable for large and complex projects, with Hooks and virtual DOM improving performance and maintainability, but the learning curve is steeper.

The future trends and forecasts of Vue.js and React are: 1) Vue.js will be widely used in enterprise-level applications and have made breakthroughs in server-side rendering and static site generation; 2) React will innovate in server components and data acquisition, and further optimize the concurrency model.

Netflix's front-end technology stack is mainly based on React and Redux. 1.React is used to build high-performance single-page applications, and improves code reusability and maintenance through component development. 2. Redux is used for state management to ensure that state changes are predictable and traceable. 3. The toolchain includes Webpack, Babel, Jest and Enzyme to ensure code quality and performance. 4. Performance optimization is achieved through code segmentation, lazy loading and server-side rendering to improve user experience.

Vue.js is a progressive framework suitable for building highly interactive user interfaces. Its core functions include responsive systems, component development and routing management. 1) The responsive system realizes data monitoring through Object.defineProperty or Proxy, and automatically updates the interface. 2) Component development allows the interface to be split into reusable modules. 3) VueRouter supports single-page applications to improve user experience.

The main disadvantages of Vue.js include: 1. The ecosystem is relatively new, and third-party libraries and tools are not as rich as other frameworks; 2. The learning curve becomes steep in complex functions; 3. Community support and resources are not as extensive as React and Angular; 4. Performance problems may be encountered in large applications; 5. Version upgrades and compatibility challenges are greater.

Netflix uses React as its front-end framework. 1.React's component development and virtual DOM mechanism improve performance and development efficiency. 2. Use Webpack and Babel to optimize code construction and deployment. 3. Use code segmentation, server-side rendering and caching strategies for performance optimization.

Reasons for Vue.js' popularity include simplicity and easy learning, flexibility and high performance. 1) Its progressive framework design is suitable for beginners to learn step by step. 2) Component-based development improves code maintainability and team collaboration efficiency. 3) Responsive systems and virtual DOM improve rendering performance.

Vue.js is easier to use and has a smooth learning curve, which is suitable for beginners; React has a steeper learning curve, but has strong flexibility, which is suitable for experienced developers. 1.Vue.js is easy to get started with through simple data binding and progressive design. 2.React requires understanding of virtual DOM and JSX, but provides higher flexibility and performance advantages.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
