Add toggle for Generated Site redirect on non-existent routes

Recently I have come across am issue with the non-existent routes redirect, since I use React router with BrowserRouter the react app has a page for some paths, but those paths don’t have an index.html file, and creating an index.html for each page can quickly become tiring and a mess, and for apps that has dynamic paths, like it isn’t possible to do using simple browser router.

So the idea is have a toggle for the redirect, leaving the handling of 404 to the project, but without affecting existing Generated Satic projects

There’s been a similar feature request here :slight_smile:

I agree this becomes somewhat problematic with SPAs.

That request is the one that got the redirect to exist on glitch actually, this one is suggesting a toggle for that request.

Hi @Awakened-Redstone would you mind confirming that the technique here doesn’t work for you?

For example if I remix the current Glitch Hello React starter project and add the changes in this tutorial any non existent route returns the Not Found page:

However I’m not sure if this works with however you’re generating your dynamic paths / using browser router etc. Let me know if you still can’t get the behavior you need!

The current solution I have can be seen on
On that project I have a script on the vite config to generate template html files for the pages, but they have to be manually added, but if I do something like it will redirect to works since I made it generate about/index.html on the build folder

On my site I have a 404 route, but it is never shown when on production mode since it gets redirected to root path. On development mode, since it doesn’t redirect, it does show the 404 page


Thanks for the additional info - passing it all back to the team and will let you know anything I find out!

OK so it sounds like it would be problematic to provide a toggle for the redirecting but hopefully we can figure out how to create the behavior you’re looking for within your project. Can you provide a little more detail about why you have your routing setup the way you do / what the end result you’re looking for is?