角度ui-router在刷新页面时发现问题

时间:2016-11-16 14:12:13

标签: angularjs angular-ui-router

在我的应用程序中,auth成功时,我正在重定向到/users。它工作正常,我也在用户页面。但是当我刷新页面时,我收到的错误是:

  

无法获取/用户

这是什么意思?

我的基本位置/适用于login页面,当用户输入路径/login时 - 我不会重定向到/。有什么问题?

这是我的router配置:

(function(){    
    "use strict";    
    angular.module('meanOffice')
        .config(routeConfig);


    function routeConfig( $locationProvider, $stateProvider, $urlRouterProvider ){

        $stateProvider
            .state('login', {
                url:'/',
                templateUrl : 'app/views/pages/login/login.html',
                controller  : 'mainController as main'
            })
            .state('users', {
                url:'/users', //refresh getting error
                templateUrl : 'app/views/pages/users/users.html',
                controller  : 'usersController as users'
            })


        $locationProvider.html5Mode({
            enabled: true,
            requireBase: false
        });


        $urlRouterProvider.otherwise('/');//when type '/login' throw error

    }

})();

2 个答案:

答案 0 :(得分:1)

这意味着您的服务器设置不正确。

为了使用HTML5模式,所有请求都需要指向您的入口点。 有关如何设置服务器的详细信息,请参阅:https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode

答案 1 :(得分:0)

设置您的快速应用:

app.route('/*').get(function(req, res) { 
    return res.sendFile(path.join(config.root, 'index.html')); 
});