If your UI is blank, open the console, and you will probably have some errors that read something along the lines of cannot use 'useNavigate' outside of context
. This means there are React Router api’s that are still imported and referenced that you need to find and remove. The easiest way to make sure you find all React Router imports is to uninstall react-router-dom
and then you should get typescript errors in your files. Then you will know what to change to a @tanstack/react-router
import.
Here is the example repo
npm i @tanstack/react-router
createBrowserRouter
or BrowserRouter
), Routes
, and Route
Components from main.tsxrender
function for custom setup/providers - The repo referenced above has an example - This was necessary in the case of Supertokens. Supertoken has a specific setup with React Router and a different setup with all other React implementationsLink
component with @tanstack/react-router
Link
component
to
prop with literal pathparams
prop, where necessary with params like so params={{ orderId: order.id }}
useNavigate
hook with @tanstack/react-router
useNavigate
hook
to
property and params
property where neededOutlet
's with the @tanstack/react-router
equivalentuseSearchParams
hook from React Router, move the search params default value to the validateSearch property on a Route definition.
useSearchParams
hook, use @tanstack/react-router
Link
's search property to update the search params stateconst { page } = useSearch({ from: productPage.fullPath })
useParams
hook, update the import to be from @tanstack/react-router
and set the from
property to the literal path name where you want to read the params object from
orders/$orderid
.useParams
hook we would set up our hook like so: const params = useParams({ from: "/orders/$orderId" })
params.orderId
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.