IE9 PathLocationStrategy Angular 4
IE9 PathLocationStrategy Angular 4
我在 Angular4 中使用 IE9 和 PathLocationStrategy,但它似乎无法正常工作。它只是附加“#”无限时间。我尝试添加 history.js polyfill 但似乎没有任何效果。
谁能帮助我如何在 Angular 4 和 IE9 中使用 PathLocationStrategy?
更新:
我终于得出结论,我们不能在 IE9 上使用 PathLocationStrategy。现在我想弄清楚如何在浏览器的其余部分使用 PathLocationStrategy,并且仅当存在 IE9 时,切换到 HashLocationStrategy。
我试图在我的模块中包含以下代码行:
RouterModule.forRoot(COMMON_ROUTES, { useHash: !Boolean(history.pushState) }),
我证实,!Boolean(history.pushState)
returns 在 IE9 中为真,在其余浏览器中为假。但它不起作用。 Angular 即使在 IE9 中也默认为 PathLocationStrategy。有人可以帮忙吗?
原因
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.
解决方案
很遗憾没有解决方案...
如 documentation 中所述,HashLocationStrategy 在引导过程中启动。
... You can switch to the HashLocationStrategy with an override during the bootstrapping process if you prefer it.
这进一步加强了...
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.
即您需要开发内容以使用特定的位置策略,而更改策略将意味着您必须在开发过程中更新重要的逻辑和其他路由功能,而不是像您希望的那样事后/在运行时进行更新。
我在 Angular4 中使用 IE9 和 PathLocationStrategy,但它似乎无法正常工作。它只是附加“#”无限时间。我尝试添加 history.js polyfill 但似乎没有任何效果。
谁能帮助我如何在 Angular 4 和 IE9 中使用 PathLocationStrategy?
更新: 我终于得出结论,我们不能在 IE9 上使用 PathLocationStrategy。现在我想弄清楚如何在浏览器的其余部分使用 PathLocationStrategy,并且仅当存在 IE9 时,切换到 HashLocationStrategy。 我试图在我的模块中包含以下代码行:
RouterModule.forRoot(COMMON_ROUTES, { useHash: !Boolean(history.pushState) }),
我证实,!Boolean(history.pushState)
returns 在 IE9 中为真,在其余浏览器中为假。但它不起作用。 Angular 即使在 IE9 中也默认为 PathLocationStrategy。有人可以帮忙吗?
原因
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.
解决方案
很遗憾没有解决方案...
如 documentation 中所述,HashLocationStrategy 在引导过程中启动。
... You can switch to the HashLocationStrategy with an override during the bootstrapping process if you prefer it.
这进一步加强了...
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.
即您需要开发内容以使用特定的位置策略,而更改策略将意味着您必须在开发过程中更新重要的逻辑和其他路由功能,而不是像您希望的那样事后/在运行时进行更新。