Mark Oliver's World

Posted: 22/03/2021

Why Can I Not Jump Direct To A Blog Post

So I thought I had got my blog up and running in Azure static web apps. It is displayed in a browser fine. I even setup a custom domain, however I cannot publish any direct post links, as it generates a 404.

It turns out this is a known issue (Thankyou Google), and I can resolve it.

The problem is because I have a Blazor WebAssembly app, there is no server to process the request at that blog post end point.
What I need to do is redirect the link back to the home page, then Blazor's dynamic routing will kick in and direct it to the correct page.
Its all down to the fact that the app is not loaded into memory UNTIL the home page has been downloaded to your browser, and generated, and can therefore do the routing.

So I need to configure a "Fallback Route"
This is done in a staticwebapp.config.json file, which should be in the app_location as defined in my github Action file

The following configuration will send all requests (except images/css) back to index.html. This should then kick the dynamic routing back in, and access the real page.

            {   "navigationFallback": {     "rewrite": "/index.html",     "exclude": ["/images/*.{png,jpg,gif}", "/css/*"]   } }
            
          

So this direct blog page link now works https://blog.markoliver.website/BlogPage/How-I-Built-This-Blog instead of giving a 404!


Thanks for reading this post.

If you want to reach out, catch me on Twitter!

I am always open to mentoring people, so get in touch.