router icon indicating copy to clipboard operation
router copied to clipboard

Support for static prefix on dynamic paths

Open FugiTech opened this issue 2 years ago • 7 comments

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

FugiTech avatar Aug 31 '23 20:08 FugiTech

Now that things are pretty stable, I'd like to see this PR updated.

tannerlinsley avatar Dec 10 '23 05:12 tannerlinsley

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

FugiTech avatar Dec 10 '23 12:12 FugiTech

Any update on this?

JacobWennebro avatar Apr 12 '24 18:04 JacobWennebro

this was closed: https://github.com/TanStack/router/pull/709

would need to be redone

schiller-manuel avatar Apr 12 '24 19:04 schiller-manuel

Any updates?

enheit avatar Aug 11 '24 08:08 enheit

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 avatar Aug 11 '24 09:08 FugiTech

@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

schiller-manuel avatar Aug 11 '24 13:08 schiller-manuel