Home > front end >  Routing in Angualr app with static directory
Routing in Angualr app with static directory

Time:09-06

With ng serve my app serves my index.html when I go to "/" in my browser then angular routing takes on so I can go to /page-b. If I refresh the /page-b in my browser, I get the actual index.html content and then angular router takes on to show my /page-b. All good here.

If I serve my app from the "/dist" folder after doing "npm build" things doesn't work when I try to refresh /page-b, since that page doesn't exist.

Where is ng serve configured to serve index.html when requesting /page-b, so that router in angular can take proper place. And what do I do so that I can serve my app from a static directory and stop having the refresh issue I am having with /page-b?

CodePudding user response:

According to https://dev.to/thedevdrawer/single-page-application-routing-using-hash-or-url-9jh

When you decide to use plain URL based routing, you need to configure the webserver to serve the index.html for SPA Route Paths

The other option is to use hash based paths in your application, so you'll always be requesting "/" but with a hash fragment that will trigger the routing.

  • Related