First Lets define Routes that will allow us to use useSearchParams in react-router v6.
<Routes>
<Route element={<SomeComponent />} path="some-route/*" />
</Routes>
Now inside the SomeComponent
const [searchParams, setSearchParams] = useSearchParams({});
setSearchParams({ hello: "world" });
console.log(searchParams);
This will set https://somevalidurl.com?hello=world
in the URL.
Top comments (0)