How to navigate back? #231
-
Whats the best way to impliment a back button? If you've entered the site on a deeply nested link, both function BackButton() {
const navigate = useNavigate();
return <button onClick={() => navigate(-1)}>Back</button>
} will take you back to the previous website. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
That sounds like the correct behavior. If you want to navigate to somewhere else, you'd need to specifically |
Beta Was this translation helpful? Give feedback.
-
A bit more context from my end might help. The examples that I gave were bad. I'm looking to emulate the behavior of twitter. Given the following link there are the following scenarios: https://twitter.com/RyanCarniato/status/1613990210169376768
What would be the best approach for this? |
Beta Was this translation helpful? Give feedback.
-
It looks like Twitter is specifically handling the click on their back arrow and deciding where to navigate themselves. Like if you inspect the button, it is not even an anchor So essentially it looks like they are maintaining their own browser history stack. Or perhaps they have a global flag they set when arriving on a Twitter page, and if that flag was not set previously then the arrow navigates to their home page instead - otherwise it does |
Beta Was this translation helpful? Give feedback.
It looks like Twitter is specifically handling the click on their back arrow and deciding where to navigate themselves. Like if you inspect the button, it is not even an anchor
<a>
and where they navigate to doesn't match the browser history.So essentially it looks like they are maintaining their own browser history stack. Or perhaps they have a global flag they set when arriving on a Twitter page, and if that flag was not set previously then the arrow navigates to their home page instead - otherwise it does
navigate(-1)
like normal ...something hacky like that.