Devserver with html5 mode urls - avoiding the 404


#1

I’d love it if the devserver had a --html5 switch, or something similar to it. I commented on the github issue that this is pretty easy to fix in the specific situation of My App, at least, I’m not sure if there are more complexities people are dealing with.

The problem is that if you’re using the html5 routing mode, you get urls like /things/1 instead of #/things/1, and that hitting reload in the browser window nets you a 404, because /things/1 is of course sent to the server and routed to “hey, we don’t have that”.

The way I have solved this in the past when I did my own build tooling (gulp, etc) was to have a fallback wildcard route that would just serve index.html. This works by injecting app.get(/^[\w\/]*$/, serveIndex); into @ionic/app-scripts/dist/dev-server.js right before return app; in createHttpServer.

I wanted to use a more complicated match than just ‘’ because that way it will still 404 if you’re referring to a resource you don’t have in assets yet, like ‘someimage.png’, whereas a '’ route would return index.html in place of the image, which causes chrome no end of headaches.

Anyway, my current approach is to manually edit the file in node_modules each time I have to, because I’m not super-excited about getting a dev environment set up for apps-scripts well enough to emit a PR on the issue. My assumption is that there’s some deeper issue here (like people want to do --http5=/devserver/prefix or something, or they want to link this to emitting a <base href="/"> into the index.html in the appropriate place, to make things much more fancy and hands-off) keeping the team from putting in the basic fix.

If it’s just “nobody’s done a PR for this and we’d accept it the way you describe it”, I’ll accept the work of forking and doing a PR, as this causes me pain every so often (whenever I get a new apps-scripts in my node_modules, which has lately been fairly often, as I’m testing deployments).