Repository navigation
Optional params? #146
Replies: 5 comments 24 replies
|
Just use the same options for both the root route and param route.
Tanner Linsley
…On Dec 9, 2021, 2:55 PM -0800, Martin Hernández Alvarado ***@***.***>, wrote:
In react router v6 they are no longer supported.
for example clients/:id? would match both /clients or /clients/1
Is there a way to achieve something like this in react location?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
|
@tannerlinsley or I would have to declare 2 two routes, one with the param and one without it? const route1 = new Route({
path: 'user',
...
})
const route1 = new Route({
path: 'user/$userID',
...
}) |
|
@tannerlinsley Is there a plan to make this more ergonomic? Something similar to react-router https://reactrouter.com/en/main/route/route#optional-segments? It's really annoying at the moment to support that exact pattern from the react-router link above, that is to have a lang param that sits at the root of your routes. You can declare two different routes, one for An alternative is to redirect on "/" to "/en" (if you're doing i18n), similarly to tanstack.com: That would work really nice for the docs as well |
|
Our team is considering migrating from React Router to TanStack router, but this is the only blocker. We have these paths
We want to render the SkillPage component for two cases and type-safely use the parameters inside const skillId = useParams({
from: `skill/$skillId`,
select: (params) => params.skillId,
});This is how we determine whether the skill is created or not. |
|
For someone needed a updated answer it is already supported https://tanstack.com/router/v1/docs/framework/react/guide/path-params#defining-optional-parameters Optional parameters create flexible URL patterns: /posts/{-$category} matches both /posts and /posts/tech |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
In react router v6 they are no longer supported.
for example
clients/:id?would match both/clientsand/clients/1Is there a way to achieve something like this in react location?
All reactions