http:// localhost:3000 /#!/为什么我的localhost链接中会出现"#!/".

Sül*_*kin 2 angularjs angular-ui-router

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

我无法弄清楚为什么会这样.

一些帮助会很棒.

小智 5

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

.config('$locationProvider', function($locationProvider){
    $locationProvider.html5Mode(true);
})
Run Code Online (Sandbox Code Playgroud)

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