Possible to go back with the Link component?
I have a question regarding whether it is possible to use the <Link> component, to go back?
Use Case:
This is a basic idea of my routes set-up which are functioning as expected.
On both the
/ and /agreements page, I have links present that would direct the user to the /agreements/$agreementId page. In the future, I have more Links than take the users to this page.
What I'm looking to do, is to add a visual element on the page for the user to be able to click on (aside from the browser back button) , to take them back to the previous page. I'd prefer it to be a <Link> component since it is Cmd+Click-able.
Currently, I'm using the useRouter() 's router.history.back() function and tying it the onClick of button element, since using a <Link> component and handling its onClick just seems a bit weird and rather redundant.
Note
I'm on @tanstack/react-router@0.0.1-beta.38 using a standard Router (not a hash or memory).
An idea of what this "visual element" I'm talking about is.... its basically my own back-button, but within the bounds of the application. ->
5 Replies
extended-salmon•3y ago
router.history.go(-1) should work for you
absent-sapphireOP•3y ago
This would be on a Button element yes?
My question was rather along the lines of is there a way to "go back", using the <Link /> component?
extended-salmon•3y ago
I can’t remember. Is there a go prop on link?
absent-sapphireOP•3y ago
Doesn't seem to have one.

extended-salmon•3y ago
Hmm
Then you’ll need to create your own component for it for now.