T
TanStack3y ago
automatic-azure

Link state prop

Is there an example of how to use the state property on a link component / navigate function? Also, I'm not sure if that's the place to pass additional data not included in the URL between routes or if there's another recommended way of doing that.
5 Replies
ambitious-aqua
ambitious-aqua3y ago
No example yet, but you should be able to just pass a state: {} property to either <Link state={{}}> or navigate({ state: {}})
automatic-azure
automatic-azureOP3y ago
Sounds great I'll try that. Thanks. I tried supplying a state object like this:
navigate({
to: "/test-page",
state: { test: "test" },
});
navigate({
to: "/test-page",
state: { test: "test" },
});
And was using
router.state.location.state
router.state.location.state
to read it on the resulting page, but can only seem to log an id like this:
{id: '16705398874410.018178662489744868'}
{id: '16705398874410.018178662489744868'}
ambitious-aqua
ambitious-aqua3y ago
Looks like a bug. Will you file an issue?
automatic-azure
automatic-azureOP3y ago
Yeah, I'll get an issue created. Thanks for the help.
automatic-azure
automatic-azureOP3y ago
GitHub
Link state missing on navigation · Issue #445 · TanStack/router
Describe the bug The Link/navigate state property doesn&#39;t pass the state to the provided route on navigation. Your Example Website or App https://stackblitz.com/edit/github-hqyitv?file=src%...

Did you find this page helpful?