51 ms·
I actually think the link solution in the Codepen box shows perfectly what's wrong with the link solution: Links should (and do by browser default) maintain the
by hn_throwaway_99 4y ago
I actually think the link solution in the Codepen box shows perfectly what's wrong with the link solution: Links should (and do by browser default) maintain their history state, while buttons do not. If you don't want to maintain the change in back button state, don't use a link.
If in his link example I click the "Open Theme Controler" link, then click the "Close" link, and do that a couple times, when I then click the back button to come back to Hacker News, I'm instead cycled through the number of times I clicked those links. I doubt any user would expect that to happen.
- eyelidlessness 4y agoI was writing this corollary to the new tab rule of thumb, with the exact example of CodePen embeds, but backed out to see if someone else added it already. Drives me bonkers every time my browsing history gets polluted by storing local state in the URL. And now that I think of that phrasing, I think that probably the unifies the rules of thumb: if it changes local state, it’s a button. If it changes local scope, it’s a link.
- graftak 4y agoThat’s because they implemented the link using history.pushState (default non-js link behaviour) when history.replaceState should be used instead. It might still be valid to use a link for an on-page modal, for instance when it needs to be navigationable or should persist on a refresh.
- hn_throwaway_99 4y ago> (default non-js link behaviour) I mean, that's pretty much my whole point. Forget javascript (as the example in the article does), but links by default append to the state, because that is pretty much how browsers always worked before they even exposed the history API to javascript.