$location in HTML5 mode requires a tag to be present!

使用locationProvider服务报错:Error:[location:nobase] $location in HTML5 mode requires a tag to be present!

AngularJS 1.3版本之前,不需要设置base标签。 我使用的是1.4.7所以需要同时添加base标签和$locationProvider

解决方法如下:

1、在head里面添加base标签

<head>
    <meta charset="UTF-8">
    <base href="/">
</head>

2、配置$locationProvider

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

参考资料
http://www.codexiu.cn/javascript/blog/31552/

猜你喜欢

转载自blog.csdn.net/innovate1989/article/details/82885731
tag