#Setting global search params

6 messages · Page 1 of 1 (latest)

spice cypress
#

Hi, so I have this setup

export const rootRoute = createRootRoute({
  component: Root,
  notFoundComponent: NotFound,
  validateSearch: z.object({
    support: z.boolean().optional(),
  }),
});

and then in Root component I have this logic:

const { search } = useLocation();
...
<SupportDialog open={search.support} onClose={onDialogClose} /> // dialog that I want to be able to open from anywhere

which works fine however when I try to set this search from somewhere I get a type error

const navigate = useNavigate();

navigate({ search: { support: true } }) // Object literal may only specify known properties ... 

as far as I understand I have to either provide "to" or "from" to navigate but I dont want to change the route I want to show the dialog on top of current page (and I dont know how to get "from" either). How can I do this properly?

spice cypress
#

but wait "to": "." seems to do the trick!!

solemn karma
#

Yeap, thats right check the docs

#

In the docs they mentioned how to do it in search param section