http:// localhost:3000 /#!/为什么我得到"#!/"在我的localhost链接中。

时间:2017-07-24 04:03:36

标签: angularjs angular-ui-router

我正在使用Angularjs构建一个网络应用,但当我进入我的索引页面时,我得到了http://localhost:3000/#!/而不是http://localhost:3000/

我无法弄清楚它为什么会发生。

一些帮助会很棒。

1 个答案:

答案 0 :(得分:5)

hashBang#!通常在url和angular路径之间添加angularjs。您可以使用$ locationProvider在.config()中禁用它,并将html5Mode设置为true,如下所示:

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

使用HTML5模式需要在服务器端重写URL,基本上您必须重写所有指向应用程序入口点的链接(例如index.html)。需要<base>标记对于这种情况也很重要,因为它允许AngularJS区分作为应用程序库的url部分和应用程序应该处理的路径。有关详细信息,请参阅AngularJS Developer Guide - HTML5 Mode Server Side