3 ms·
You don't make a single page application by adding links to other pages.
by edflsafoiewq 4y ago
You don't make a single page application by adding links to other pages.
- tshaddox 4y agoSure you do. You use the Link component (or similar) that’s provided by the SPA router, which renders a normal <a href="cool-page"> tag that works fine with middle-clicking, command-clicking, and right-clicking. The only difference is that it overrides the click event to perform a client-side navigation on normal clicks. You have to go out of your way to make this not work, or I suppose you could implement your own SPA framework and not understand how any of this works.
- chrismorgan 4y agoI’ve never liked the <Link> approach. I much prefer to write normal links throughout and intercept clicks globally, which is easier to work with, and every bit as reliable (more, in some situations). See https://news.ycombinator.com/item?id=31366875 https://news.ycombinator.com/item?id=31366875 for some discussion of this approach, with sample code in https://news.ycombinator.com/item?id=31373486 https://news.ycombinator.com/item?id=31373486.
- tshaddox 4y agoYeah, that works well too, it just isn't as common in component-based frameworks for the reasons pointed out in that thread.
- chrismorgan 4y agoBut I also debunked those reasons in-thread: the URL is fundamentally global state, so there’s no virtue in avoiding a global event handler—in fact, there is virtue in using a global event handler, because the alternative encourages inconsistency, with regular page-load routing accidentally not working in parts of the system (and I’ve definitely seen this happen in real life).