You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Considering a route like:
/users/$userId/details
/users/$userId/posts
/dummy/$dummyId
If we have a component that is used in the users routes that knows how to navigate to a different user, keeping the current location (details or posts),
then we can use the navigate returned from useNavigate to do so. It was suggested not to provide a to to have this working properly, and it works but Typescript complaints:
with navigate({ params: { userId: value }}); it complains that Object literal may only specify known properties, and userId does not exist in type
with navigate({ params: (prev) => ({...prev, userId: value })}); it complains that the { userId: string } is not assignable to type never
Using the from or the to, parameters solves the typescript issue, but we need to use a specific route otherwise we lose the current location,
One possibility is to use, but it might be overcomplicating the solution.
const matches = useMatches();
const to = matches[matches.length - 1].fullPath;
navigate({to, params: { userId: value });
This issue is a followup of the discussion on Discord
Which project does this relate to?
Router
Describe the bug
Considering a route like:
/users/$userId/details
/users/$userId/posts
/dummy/$dummyId
If we have a component that is used in the users routes that knows how to navigate to a different user, keeping the current location (details or posts),
then we can use the navigate returned from useNavigate to do so. It was suggested not to provide a
to
to have this working properly, and it works but Typescript complaints:navigate({ params: { userId: value }});
it complains thatObject literal may only specify known properties
, and userId does not exist in typenavigate({ params: (prev) => ({...prev, userId: value })});
it complains that the{ userId: string } is not assignable to type never
Using the
from
or theto
, parameters solves the typescript issue, but we need to use a specific route otherwise we lose the current location,One possibility is to use, but it might be overcomplicating the solution.
This issue is a followup of the discussion on Discord
Your Example Website or App
https://stackblitz.com/edit/tanstack-router-xlb7ip?file=app%2Fcomponents%2FNextUserNavigator.tsx
Steps to Reproduce the Bug or Issue
Use navigate to change only one parameter keeping any sub-route.
Expected behavior
A cleaner way to change only the parameter without TS complaints.
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: