禁用角度ui路由器中的#

时间:2014-11-26 06:01:18

标签: angularjs angular-ui-router

如何删除'#'来自角度ui-router的网址。

app.config(['$locationProvider', function($locationProvider) {
    $locationProvider.html5Mode(true);
}]);

上述事情并不奏效。它适用于我们点击ui-sref属性的时候,但是当我想直接转到某个链接时,它就没有了。

EG。 当我在http://www.example.com上点击一个元素并使用ui-sref ="关于"时,我需要http://www.example.com/about。但如果我通过输入网址到达http://www.example.com/about,则会出错。

1 个答案:

答案 0 :(得分:1)

Angular app是一个单页应用程序。

基本上,当您在应用程序的路由器中导航时,应用程序将删除哈希(如果存在),因为您在$locationProvider.html5Mode(true)中进行了配置。

但是如果您在浏览器中输入网址,它就会成为角度应用的外部网址。路线/about在技术上并不存在。尝试在您的网址中输入http://www.example.com/#/about#将被删除。