S
SolidJS4mo ago
Joe Pea

solid-router: navigate(-1) or navigate(path)? How do we know which?

There's a probably not uncommen scenario in routing: you navigate somewhere, then the app has a button to go back. For example, if you're on a home page, and you click a user profile, the back button could just run navigate(-1) and you'll be back at the home page, one entry previous in the browser history. But... what if you didn't start at the home page? For example, what if you copy/pasted the user profile URL into a new tab? It would no longer make sense for the back button to call navigate(-1) because there's nothing to go back to. So in this case it would make more sense for it to call navigate('/'), adding a new entry in the browser history. Is there a solution to this to make it easy? What's the best behavior? Should we just always call navigate('/') instead of navigate(-1) and make a new history item each time? Seems like the easy solution is to make a new history item each time, forget about navigate(-1).
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server