Index.html and SPA


#1

Hello. I have a single page app with index.html file located in public dir. In route.js file i send index.html to user for each route that didn’t match any route above, as guide suggest. But i found out, that for root ‘/’ route the /public/index.html file would be send to user bypassing SPA ‘*’ route. This could be unexpected, especially if we want to use some named middlewares with SPA route. Probably some remarks for docs could be provided. Thank you.


#2

Hey @1001v! :wave:

I’m sorry, but I didn’t get your issue with the router and your SPA.
May you clarify this? (it could be great to add some code/example)


#3

Hey. That’s not really an issue, as i think. Probably that’s a conflict between SPA route and Static route to public dir.
Let say we want a SPA: we have an index.html file in public dir and we write route like this:
Route.any('*',({response}) => response.download(Helpers._appRoot + '/public/index.html')
The problem is that request to root route will respod an index.html file as it’s a static asset. Of course that’s what browsers do, they ask server for index.html file, when no route provided. This could be a litte unexpected since we added Route.any(’*’) and wanted it to serve any non-api request.
In a nutshell: i suggest to add an advice to docs not to name your SPA base file index.html, it should be something else, maybe main.html. For example i wanted to add middlewares to Route.any, but they didn’t work. I spent some time to realize what’s going on. Maybe it’s only me so stupid, but i’m sure someone should use this experience. Thank you.

P.S. I see what my usage of Helpers provider doesn’t look like expected. I just didn’t find any docs about it.