Web 应用程序中的 PathLocationStrategy 与 HashLocationStrategy [英] PathLocationStrategy vs HashLocationStrategy in web apps

查看:19
本文介绍了Web 应用程序中的 PathLocationStrategy 与 HashLocationStrategy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用的优缺点是什么:

  1. PathLocationStrategy - 默认的HTML 5 pushState"样式.
  2. HashLocationStrategy - 哈希 URL"样式.

例如,使用 HashLocationStrategy 将阻止通过 #ID 滚动到元素的功能,但某些 3rd 方插件需要 HashLocationStrategyHashbang #! 以便在 ajax 网站中工作.

for instance, using HashLocationStrategy will prevent the feature of scrolling to an element by its #ID, but some 3rd party plugins require the HashLocationStrategy or the Hashbang #! in order to work in ajax websites.

我想知道哪一个提供更多的网络应用程序.

I would like to know which one offers more for a webapp.

推荐答案

对我来说主要的区别在于 PathLocationStrategy 需要在服务器端对 @ 中配置的所有路径进行配置RouteConfig 重定向到 Angular2 应用程序的主 HTML 页面.否则,当您尝试在浏览器中重新加载您的应用程序或尝试使用特定 URL 访问它时,您将遇到一些 404 错误.

For me the main difference is that the PathLocationStrategy requires a configuration on the server side to all the paths configured in @RouteConfig to be redirected to the main HTML page of your Angular2 application. Otherwise you will have some 404 errors when trying to reload your application in the browser or try to access it using a particular URL.

这里有一个问题可以给你一些提示:

Here is a question that could give you some hints about this:

希望对你有帮助蒂埃里

这篇关于Web 应用程序中的 PathLocationStrategy 与 HashLocationStrategy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆