-
-
Notifications
You must be signed in to change notification settings - Fork 668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for static prefix on dynamic paths #707
Comments
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: #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 |
Hey would love to chime in here as this is currently kinda a roadblocker for me to potentially migrate our platform to Start as we have /@username paths. What about support Maybe this has already been discussed and SvelteKit and Rakkas do their params this way so automatically support |
Trying to implement something, at least hacky as an example tho so far I'm failing pretty ungracefully 😅 export interface Segment {
type: 'pathname' | 'param' | 'wildcard'
value: string
params?: Record<string, string>
} or a discriminated union, so that the example path with a route like {
type: 'param',
value: 'prefix-p2-p2',
params: {
param1: 'p1',
param2: 'p2'
}
} |
My last attempt failed by producing an (infinite) redirection loop appending the path params over and over again 😭 😅 |
I really do want to support this. I'm just not sure what it would take on the type side just yet. I admittedly have been focused on other things. @chorobin @schiller-manuel and @SeanCassiere might continue to gain insights here, but until I ship Start beta, I can't really dive in here 100% yet. |
Okay I see, really appreciate your comment 🙏🏼 |
Got a very first version hacked together, works with prefix: Also currently NO Typescript support and I'm not sure I can fix that myself 😇 Gonna play a little more with it and then prepare a (draft) PR (probably not tomorrow) so team could have a look whenever they have capacity. The Edit: By the way this is not a breaking change, everything else should work as before, so you can still use Edit2: Actually it already supports multiple dynamic parameters in a single path segment |
I'm all for this being implemented, but in the meantime, it shouldn't be a hard blocker. Here's a tested workaround: // routes/$username.tsx
import { createFileRoute, notFound } from "@tanstack/react-router";
export const Route = createFileRoute("/$username")({
component: RouteComponent,
beforeLoad: ({ params: { username } }) => {
// You can use your own check of course
if (!username.startsWith("@")) {
notFound({ throw: true });
}
},
});
function RouteComponent() {
const params = Route.useParams();
const username = params.username.substring(1);
return `Hello ${username}!`;
} You could also put it in your context. |
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 exampleyoutube.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
This will not be recognized as a dynamic route and
var
will not be available inparams
Expected behavior
var
would be available inparams
Screenshots or Videos
No response
Platform
N/A
Additional context
No response
The text was updated successfully, but these errors were encountered: