How to programatically create and copy route URLs? #1391
Unanswered
jameslawson
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
I'm migrating my app from react-router to tanstack/router. I'm current stuck migrating a feature where users can click a menu item that copies a URL to the clipboard.

This menu component is reusable and used in a few screens: the component itself doesn't know exactly what to copy, this info passed down via a React prop.
With react-router:
generatePath
to generate a stringurl
.window.location.href
to clipboard because for this particular app, only certain parts of the URL are important for the permalink and other parts should be ignoredQuestion: What's the best approach for migrating this to tanstack-router?
Code
Before migration (react-router)
After migration (tanstack/router) ??
I figured I could pass ToOptions down to the component and let it generate the full URL. But I'm encountering type errors.
app/router.ts
It seems I can't pass an object of type
ToOptions
touseLinkProps
(which is little bit unexpected for me)?I can't find any examples for the intended use of
useLinkProps
, are we supposed to be able to passToOptions
touseLinkProps
? And if not is there an alternative approach where I can programatically generate a full url using the state: from/to/params/search? The ancestor react components have access to all this state data and can pass down what's needed. Here I'm looking for the simplest and most idiomatic way for this component to programatically generating the URL given this state with tanstack/router.Loving tanstack/router so far! Thank you for your time! 🙏
Versions:
Beta Was this translation helpful? Give feedback.
All reactions