T
TanStack3y ago
absent-sapphire

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.
/ -> Dashboard/Home page
/agreements -> Search page
/agreements/$agreementId -> Agreement View Page ($agreementId is variable)
/ -> Dashboard/Home page
/agreements -> Search page
/agreements/$agreementId -> Agreement View Page ($agreementId is variable)
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).
export const router = createReactRouter({
routeConfig,
parseSearch: parseSearchWith((value) => JSON.parse(decodeFromBinary(value))),
stringifySearch: stringifySearchWith((value) =>
encodeToBinary(JSON.stringify(value))
),
});
export const router = createReactRouter({
routeConfig,
parseSearch: parseSearchWith((value) => JSON.parse(decodeFromBinary(value))),
stringifySearch: stringifySearchWith((value) =>
encodeToBinary(JSON.stringify(value))
),
});
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. ->
No description
5 Replies
extended-salmon
extended-salmon3y ago
router.history.go(-1) should work for you
absent-sapphire
absent-sapphireOP3y 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
extended-salmon3y ago
I can’t remember. Is there a go prop on link?
absent-sapphire
absent-sapphireOP3y ago
Doesn't seem to have one.
No description
extended-salmon
extended-salmon3y ago
Hmm Then you’ll need to create your own component for it for now.

Did you find this page helpful?