If you’re building a Single Page Application (SPA) then routing tends to be taken care of on the client side by your index.html root document which requires it to be loaded first.

If you’re hosting your site as a static site in Azure storage and you reefresh the page then you’ll likely get a 404 error rather than the required page due to the fact that Azure tries to determine the route first before passing the request to your site which means anything other than the root URL will fail.

The quick and dirty way to get around this is to set the error document path to be index.html which means when Azure fails to find the route it will direct the request to the index.html document which will render the route client side. The downside of this approach is that the browser will also report a 404 error, but at least the requested page will render.

A better solution is to use the Azure CDN to direct all requests to the index.html file as discussed here. This is a bit more work to set up and has a minimal cost but avoids any 404 errors.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.