架构师_程序员_码农网

Retrieve password
Register

QQ登录

Just one step to get started

Search
View:7385|Reply: 0
打印 上一主题 下一主题

[Angular]Angular Routing Hash Patterns and HTML5 Patterns

[Copy Link]
跳转到指定楼层
owner of the building
发表于 2020-5-28 16:35:03| 看该作者回帖奖励|ReverseBrowse|Read Mode
Two strategies for routing

  • PathLocationStrategy - Default strategy, supports "HTML 5 pushState" style.
  • HashLocationStrategy - Supports "hash URL" 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 application is in production, it's not easy to change it because there are already a lot of references to the application URL out there.

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

Rendering a given page server-side is a technique that can dramatically improve the responsiveness of the app when it first loads. Apps that would otherwise take ten seconds or more to load can be pre-rendered server-side and rendered in their entirety 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 the HTML5 History mode by default.

The url is similar to http://localhost:4200/task-list, which is a more comfortable and aesthetically pleasing URL to look at.

The URL is more comfortable to look at and more aesthetically pleasing. Refreshing the routing page will result in a 404.

There is another mode, hash mode.

The url is similar to http://localhost:4200/#/task-list.

If you jump to the route page and refresh it again, it will still stay in the current route.

How to enable hash route mode

In app.module.ts, introduce and provider






Previous: sql server query current system time of the previous days
Next: CSS set height:100% invalid solution
The code farmer network, only published in the process of practice, encountered technical difficulties, do not mislead others.
You need to log in before you can post back Log in | Register

This version of the integral rules

DISCLAIMER:
All software, programming materials or articles released by the code farmer network is limited to study and research purposes; shall not be used for commercial or illegal use of the above content, otherwise, all the consequences of the user please be responsible for their own. This site information from the network, copyright dispute has nothing to do with this site. You must completely remove the above content from your computer within 24 hours of downloading. If you like the program, please support the genuine software, buy registration and get better genuine service. If there is any infringement, please contact us by email to deal with it.

Mail To:help@itsvse.com

QQ| ( ICP备14021824号-2 )|Sitemap

GMT+8, 2024-9-18 22:19

Quick ReplyBack to topBack to list