This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15174|Reply: 0

[Angular] Angular routing hash pattern and HTML5 pattern

[Copy link]
Posted on 5/28/2020 4:35:03 PM | | |
Two strategies for routing

  • PathLocationStrategy - The default policy, supporting the "HTML 5 pushState" style.
  • HashLocationStrategy - Supports the "hash URL" style.

Which strategy is better?

You have to choose a strategy and do it early in the project. Once the app is in production, it is not easy to change it because there are already a lot of references to the app URL.

Almost all Angular projects use the default HTML 5 style. The URLs it generates are easier for users to understand, and it also leaves room for server-side rendering in the future.

Rendering a given page on the server side is a technique that can greatly improve the responsiveness of the app when it first loads. Apps that would otherwise take ten seconds or more to load can be rendered on the server side in advance and rendered on the user's device in less than a second.

This option only works if the app's URL looks like a standard web URL with no hash(#) in the middle.

Unless you have a strong reason to use hash routing, you should stick to the default HTML 5 routing style

angular-cli uses HTML5 History mode by default,

url-like http://localhost:4200/task-list,

URLs look more comfortable and beautiful. Refreshing on the routing page will result in 404

There is also a pattern that is the hash pattern,

url-like http://localhost:4200/#/task-list,

Jumping to the route page and refreshing it will still stay on the current route.

Enable the hash routing mode method

app.module.ts introduced and provider






Previous:SQL Server queries the previous days of the current system time
Next:CSS setting height: 100% invalid solution
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com