IE9 PathLocationStrategy Angular 4

烂漫一生 提交于 2021-02-04 15:32:16

问题


I'm using IE9 and PathLocationStrategy with Angular4 but it doesn't seem to be working. It just appends "#" infinite time. I tried adding history.js polyfill but nothing seems to be working.

Can anyone help how do I use PathLocationStrategy with Angular 4 and IE9?

Update: I finally figured concluded, we cannot use PathLocationStrategy on IE9. Now I'm trying to figure out how to use PathLocationStrategy on rest of the browser and only if IE9 is present, switch to HashLocationStrategy. I tried to include following line of code inside my module:

RouterModule.forRoot(COMMON_ROUTES, { useHash: !Boolean(history.pushState) }),

I verified that, !Boolean(history.pushState) returns true in IE9 and false in rest of the browsers. But it is not working. Angular defaults to PathLocationStrategy even in IE9. Can someone help?


回答1:


The Cause

Older browsers [non-evergreen] send page requests to the server when the location URL changes unless the change occurs after a "#" (called the "hash"). Routers can take advantage of this exception by composing in-application route URLs with hashes.


The Solution

There is no solution unfortunately...

As stated in the documentation, the HashLocationStrategy is initiated during the bootstrapping process.

... You can switch to the HashLocationStrategy with an override during the bootstrapping process if you prefer it.

This is further reinforced...

You must choose a strategy and you need to make the right call early in the project. It won't be easy to change later once the application is in production and there are lots of application URL references in the wild.

i.e. you need to develop the content to use a specific location strategy and changing strategies will mean you will have to update significant logic and other routing functionality during development, not as an after-thought / at runtime like you desire.



来源:https://stackoverflow.com/questions/45881466/ie9-pathlocationstrategy-angular-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!