Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Routing in Angualr app with static directory

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading