AngularJS and Express Routing issue

后端 未结 1 538
天命终不由人
天命终不由人 2021-01-07 09:03

I\'m using AngularJS and ExpressJS and having an issue with routing. I saw many other posts but none of those solutions seemed to work. Here is my routes in Express:

相关标签:
1条回答
  • 2021-01-07 10:01

    When using html5Mode the documentation says:

    Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html)

    What it doesn't mention is:

    • You should exclude static assets like scripts/styles/images/fonts etc.
    • You should also exclude your Restful API.

    Your case:

    The error you got there is express serving html into script tags and the browser fails to parse them as a valid javascript.

    Use express.static to serve static assets and then use app.get('*', for redirecting all other requests to your angular.js entry point (index.html).

    express.js middleware order do counts!

    • express.static must be declared before app.router
    • Node.js / Express.js - How does app.router work?
    0 讨论(0)
提交回复
热议问题