router
router copied to clipboard
Link state missing on navigation
Describe the bug
The Link/navigate state property doesn't pass the state to the provided route on navigation.
Your Example Website or App
https://stackblitz.com/edit/github-hqyitv?file=src%2Fmain.tsx
Steps to Reproduce the Bug or Issue
Click on the About link in the navbar to navigate to the new route with the state printed out.
Expected behavior
I expected to see the provided state {"test":"value"} to be printed to the screen on the new route. Instead a state with a random ID gets output, e.g. {"id":"16706647803220.5453417445657511"}.
Screenshots or Videos
No response
Platform
- OS: Linux running in Windows WSL
- Browser: Chrome
- Version: 108.0
Additional context
No response
I think this is related to the second part of the issue I desribed in #444, a stackblitz example was included there as well.
Well, I can confirm this for the latest version.
This is how i navigate:
<tr
className="border-b bg-white hover:bg-gray-50 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-600"
key={id}
onClick={() => {
navigate({
to: "/user/$userId",
params: {
userId: String(id),
},
state: { user: name, username, email, phone, address },
}).then(
() => {},
() => {}
);
}}
>
And this is the view of who must receive the id and state:
const Profile: FC = () => {
const { userId } = useParams();
const router = useRouter();
const routerState = router.store.currentLocation.state;
console.log("State", routerState);
const {
data,
error,
isError,
isLoading: loadingAlbums,
} = useQuery<Album[], Error>({
queryKey: ["user", userId],
queryFn: () => service.getAlbumByUserId(Number(userId)),
});
And this is what we get on log:

Interesting.
This issue should be fixed. Reopen if you find otherwise.
I can confirm this is still an issue. State isn't being passed through to commit location.
https://github.com/TanStack/router/blob/83d8bff6009629d1ca4091dcdf602cc1835f7dd1/packages/router/src/router.ts#L799-L806
I can confirm this is still an issue. State isn't being passed through to commit location.
https://github.com/TanStack/router/blob/83d8bff6009629d1ca4091dcdf602cc1835f7dd1/packages/router/src/router.ts#L799-L806
@tannerlinsley Would it be worthy to test?
Still an issue on latest beta.
Still an issue on latest beta.
it would be nice to open a new PR for fixing it.