Express JS redirect to default page instead of “Cannot GET”

后端 未结 2 2009
醉酒成梦
醉酒成梦 2021-02-19 16:52

I am using express JS and I have a set of routes that I have defined as follows

require(\'./moduleA/routes\')(app);
require(\'./moduleB/routes\')(app);
         


        
2条回答
  •  我在风中等你
    2021-02-19 17:41

    JUst try to put one get handler with * after all your get handlers like bellow.

    app.get('/', routes.getHomePage);//When `/` get the home page
    
    app.get('/login',routes.getLoginPage); //When `/login` get the login page
    
    app.get('*',routes.getHomePage); // when  any other of these both then also homepage.
    

    But make sure * should be after all, otherwise those will not work which are after * handler.

提交回复
热议问题