我正在尝试在我的应用程序中使用Angular UI路由器。当我初始化UI路由器而不是说出来时,localhost:8000/#/
我得到localhost:8000/#!#%2F
。
我的app.js如下:
angular
.module('quiz',['ngMaterial',
'ngMessages',
'ngCookies',
'ngResource',
'quiz.routes'
]).config(function($resourceProvider) {
$resourceProvider.defaults.stripTrailingSlashes = false;
});
angular
.module('quiz.routes',['ui.router']);
在我的quiz.routes.js中,我有:
(function () {
angular
.module('quiz.routes')
.config(config);
function config($urlRouterProvider,$stateProvider){
$stateProvider
.state('register',{
url: '',
templateUrl: '/static/templates/register.html'
});
}
})();
所以不是我得到的尾随斜线!#%2F在我的网址中。这是为什么?
答案 0 :(得分:3)
假设您使用的是Angular 1.6版,则可能是因为对默认hashPrefix所做的更改现在设置为!
。要修复,您需要将$locationProvider
注入模块的config
块,并将默认的hashPrefix重置为空字符串。
$locationProvider.hashPrefix('')
这是reported as a bug here,虽然事实证明它是设计并有意改变的。