Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何启用到URL的导航';用AngularJS';什么是HTML5模式?_Javascript_Angularjs_Html_Hash_Url Routing - Fatal编程技术网

Javascript 如何启用到URL的导航';用AngularJS';什么是HTML5模式?

Javascript 如何启用到URL的导航';用AngularJS';什么是HTML5模式?,javascript,angularjs,html,hash,url-routing,Javascript,Angularjs,Html,Hash,Url Routing,我在AngularJS应用程序中启用了HTML5模式,因此我可以访问URL格式为site.com/path的路径,而不是site.com/#/path 但是,在启用HTML5模式的情况下,到哈希的导航无法正常工作。当我通过Chrome导航到site.com/#hash时,URL会自动更改为site.com/hash。由于hash不是服务器上的资源,因此此URL导致加载默认index.html文件,而不是滚动到hash位置 这似乎是一个非常简单的用例,但如何使URL格式site.com/#hash

我在AngularJS应用程序中启用了HTML5模式,因此我可以访问URL格式为
site.com/path
的路径,而不是
site.com/#/path

但是,在启用HTML5模式的情况下,到哈希的导航无法正常工作。当我通过Chrome导航到
site.com/#hash
时,URL会自动更改为
site.com/hash
。由于
hash
不是服务器上的资源,因此此URL导致加载默认index.html文件,而不是滚动到
hash
位置


这似乎是一个非常简单的用例,但如何使URL格式
site.com/#hash
与AngularJS的预期工作一致?

我得到了以下帮助:

  • 这个问题:
  • AngularJS文档中的间接提示:
从文档页面引用:

请注意,在IE9中使用$location解析相对路径时,删除标记的要求将产生不利的副作用

总之,Angular仅在以下情况下才会在URL中保留未触及的哈希片段:

  • HTML5模式已启用
  • 已设置哈希前缀
  • 在启用HTML5模式时,您没有设置
    requireBase:false

难怪人们会觉得很难理解AngularJS:文档很弱,框架就像一个神奇的黑匣子,让你无法控制你的应用程序。

删除
html5mode
代码,然后在删除html5mode后尝试使用它,URL必须是
site.com/#/#hash
,哈希才能工作,而不是
site.com/#hash
,如果添加
#hash
,它将不会产生任何问题,因为它只停留在客户端。如果我输入URL
site.com/#hash
,您是否尝试在chrome地址上直接点击barIn hashbang模式下的相同URL,Chrome将其更改为
site.com/#/hash
。然后启用
HTML5模式
,然后尝试直接点击