3 ms·
> So like, if you're on my-spa.com, and click a link to a post, the JS loads the post and updates the URL, but doesn't perform a full page load. So while you mi
by __jonas 3y ago
> So like, if you're on my-spa.com, and click a link to a post, the JS loads the post and updates the URL, but doesn't perform a full page load. So while you might be on https://my-spa.com/user/39820002/post/39811155 https://my-spa.com/user/39820002/post/39811155, your browser likely never actually sent a GET request to /user/39820002/post/39811155. But this creates the issue that if you manually navigate to that URL, your browser WILL send a request for it.
Exactly, you got it. This is why SPA configurations for webservers exist, like the SPA_MODE on the one we are commenting on.
> EDIT: I think a better way to do this hold thing is to make the resource an anchor tag in the URL. Instead of https://my-spa.com/user/39820002/post/39811155 https://my-spa.com/user/39820002/post/39811155, make it https://my-spa.com/#user/39820002/post/39811155 https://my-spa.com/#user/39820002/post/39811155
As someone else said:
https://news.ycombinator.com/item?id=39819120 https://news.ycombinator.com/item?id=39819120
Hash routes have their own problems, I don't think they are a great solution, but indeed SPA routers often support them, example from react router:
https://reactrouter.com/en/main/router-components/hash-router https://reactrouter.com/en/main/router-components/hash-route...
Note that they strongly suggest to not use hash routing unless you have no other choice.
I agree that returning 200 to every route isn't great for some scenarios, but realistically, SPAs exist, they usually work like this and they are deployed like this, can't really change that now.
I would just not build an SPA with client side routing at this point in time since there are solutions that I personally prefer, other people may think differently though.