MEAN Stack 路由问题,angular 路由不起作用

MEAN Stack routing issue, angular routing does not work

我有我的routes.js

module.exports = function(app) {
//I can't use this because angular routing does not work
/*app.get('*', function(req, res) {
    res.sendfile('./public/index.html');
});*/
    app.get('/submit', function(req,res){
        res.sendfile('./public/submit.html');
    }); 

    app.get('/schedule', function(req,res){
        res.sendfile('./public/schedule.html');
    }); 

    app.get('/requests', function(req,res){
        res.sendfile('./public/requests.html');
    });

    app.get('/tv_left', function(req,res){
        res.sendfile('./public/tv_left.html');
    });

    app.get('/tv_center', function(req,res){
        res.sendfile('./public/tv_center.html');
    });

    app.get('/tv_right', function(req,res){
        res.sendfile('./public/tv_right.html');
    });

    app.get('/', function(req, res){
        res.sendfile('./public/index.html');
    });
};

我的appRoutes.js喜欢这样

angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {

    $routeProvider

        // home page
        .when('/', {
            templateUrl: 'index.html',
            controller: 'LoginController'
        })

        .when('/submit', {
            templateUrl: 'submit.html',
            controller: 'SubmitController'
        });

    $locationProvider.html5Mode(true);

}]);

基本上,如果我使用 app.get('*'),那么任何请求都会返回到 index.html,即使 url 已更改。

这是因为 express 按照定义的顺序处理路由。如果你想 index.html 作为一个包罗万象的路线,把它移到函数的底部。

进一步阅读:https://www.safaribooksonline.com/blog/2014/03/10/express-js-middleware-demystified/