node.js/angular.js - Cannot GET

前端 未结 4 1137
渐次进展
渐次进展 2021-02-07 11:22

I have the root route and it works fine. I also have a another route 127.0.0.1:3000/dashboard if I just type that url into the address bar I get this error:

Cannot GET /

4条回答
  •  星月不相逢
    2021-02-07 12:02

    I'd suggest a pretty fast javascript solution in front and back end.

    NodeJs

    // set up our one route to the index.html file
        app.get('*', function (req, res){
        res.sendFile(path.join(__dirname+'/public/index.html'));
    });
    

    This code tells to de local/remote server where is the main html, so it could find the rest of templates.

    AngularJs

    // If 404 Redirect to home
    $routeProvider.otherwise( { redirectTo: '/'} );
    

    This is also really helpful, so never goes to a missing page.

提交回复
热议问题