0

I have my 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');
    });
};

and my appRoutes.js like this

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);

}]);

basicly if I use app.get('*'), then any request will go back to index.html, eventhough the url changed.

3
  • Are you getting an error? Please elaborate a bit more on the core issue as to what is not working Commented Jul 17, 2015 at 17:05
  • be a lot smarter to use asset directories then route anyhting that isn't a directory to index Commented Jul 17, 2015 at 17:23
  • @charlietfl what do you mean? Commented Jul 17, 2015 at 17:24

1 Answer 1

1

That's because express handles routes in the order they are defined. If you want index.html as a catch-all route, move it to the bottom of the function.

Further reading: https://www.safaribooksonline.com/blog/2014/03/10/express-js-middleware-demystified/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.