Currently I have
createBrowserRouter(
createRoutesFromElements(...)
);
and nested within there is a:
<Route index element={<Navigate to="/raters/start/" />} />
This works fine for the base URL, except that we now need to capture any query strings on the original route and pass those on when we re-route the browser.
Is there something like this functionality available?
<Route
index
path="?:queryString"
element={<Navigate to={`/raters/start?${queryString}`} />}
/>
2
Answers
Another approach is to use a loader to redirect:
The URL search string is not used for route path matching, it is invalid to include it in the
path
prop string. You’ll need to manually capture and forward the URL path + searchParams.Examples:
Custom component
Read and forward
window.location.search