router
router copied to clipboard
Support for static prefix on dynamic paths
Describe the bug
Currently TanStack Router supports dynamic path segments in the form /$var/. However it is sometimes useful to have a static prefix (or suffix) that is used as part of the matching. For example youtube.com/@ChannelName.
This is a feature request for Router to support the form /prefix$var/ (or some other way of having a static prefix mixed with a dynamic variable). Optionally it would be nice to also support suffixes, perhaps in the form /prefix$var$suffix/?
Your Example Website or App
https://stackblitz.com/edit/tanstack-router-jwzga9?file=src%2Fmain.tsx
Steps to Reproduce the Bug or Issue
new Route({
path: '/prefix$var',
component: function User({ useParams }) {
const params = useParams();
return <div className="p-2">Hello {params.var}!</div>;
},
});
This will not be recognized as a dynamic route and var will not be available in params
Expected behavior
var would be available in params
Screenshots or Videos
No response
Platform
N/A
Additional context
No response
Now that things are pretty stable, I'd like to see this PR updated.
I updated the PR to remove the merge conflicts but didn't do an in-depth look at what's changed in the last 4 months
Any update on this?
this was closed: https://github.com/TanStack/router/pull/709
would need to be redone
Any updates?
My understanding is that while this feature is something they are willing to support, it is not a high priority and nobody on the core team is working on it. (I am not a maintainer and have no real knowledge of their priorities)
I originally suggested it since it'd be useful in a project I was working on, but I have since dropped that project and am not actively using TanStack router, therefore I do not have time to implement this feature myself.
If somebody is looking for this feature, I recommend filing a PR implementing it yourself. The previously mentioned PR may be helpful as a starting point, but I imagine a lot has changed since I made it.
@FugiTech is absolutely correct. core team is not working on this feature but we are happy to accept PRs. if anyone is interested in implementing this, reach out to us e.g. via discord