Angular UI路由器初始化

时间:2017-02-12 16:25:23

标签: javascript angularjs angular-ui-router

我正在尝试在我的应用程序中使用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在我的网址中。这是为什么?

1 个答案:

答案 0 :(得分:3)

假设您使用的是Angular 1.6版,则可能是因为对默认hashPrefix所做的更改现在设置为!。要修复,您需要将$locationProvider注入模块的config块,并将默认的hashPrefix重置为空字符串。

$locationProvider.hashPrefix('')

这是reported as a bug here,虽然事实证明它是设计并有意改变的。