Search params from layout
Hi, reading search parmas from root route (layout) works
But when i try to set search params from a component rendered in this root like sidenav then
from
__root__
is not a valid type it only accepts routes. How to navigate from layouts?12 Replies
metropolitan-bronze•5mo ago
please provide a complete minimal example, e.g. by forking one of the existing stackblitz router examples
wise-whiteOP•5mo ago
@Manuel Schiller
https://stackblitz.com/edit/tanstack-router-vonreznv?file=src%2Froutes%2F__root.tsx
here u go
so nav.tsx
how can u use
useNavigate
here?
u don't know from what route u will call it
becuase its a layoutmetropolitan-bronze•5mo ago
from needs to be a path for useNavigate
so just use '/'
or dont specify anything
not required
btw don't use
__root__
directly, use
its an internal detail that could changewise-whiteOP•5mo ago
okey but
if u dont pass anything to navigate
and in this case i can't pass '/'
becuase u can call this from any rooute
then
this is type error
navigate is fully untyped
and doesnt accept
what it should
meaning
Record<string, string | string[]>
or something like this
metropolitan-bronze•5mo ago
add a
to: '.'
wise-whiteOP•5mo ago
okey now works
metropolitan-bronze•5mo ago
see also the docs
metropolitan-bronze•5mo ago
Search Params | TanStack Router React Docs
Similar to how TanStack Query made handling server-state in your React and Solid applications a breeze, TanStack Router aims to unlock the power of URL search params in your applications. 🧠 If you ar...
metropolitan-bronze•5mo ago
link and useNavigate have the same underlying api
wise-whiteOP•5mo ago
yeah i know link search but this is just minimal repro
in my case i need buttons
thanks tho
metropolitan-bronze•5mo ago
what I was hinting at is this

metropolitan-bronze•5mo ago
it's all documented