Use at your own risk! Feel free to modify. They were customized for our code base and help to automate 90% of the migration our big React Router v5 app.
You will notice some data-exact
field on routes. Those are only needed while you have some merge requests still on v5 and some on v6. When your whole code base (including pending merge requests) is using v6 you can safely delete all those ESLint rules and you can just run a string-replace on your code base to remove data-exact="true"
and data-exact="false"
.
My two biggest gotchas during the migration:
- remix-run/react-router#8035 (comment)
- removing
state
fromto
Regarding the first point we created this file src/components/root-routes
that is also expected by one of the ESLint Rules:
/* eslint-disable rulesdir/rrv6-migrate-root-routes */
// for an easier migration we nest <Routes/> and use absolute paths.
// but this currently requires a workaround.
// see https://github.com/remix-run/react-router/issues/8035#issuecomment-997737565
// with a bit of luck this becomes officially supported (https://github.com/remix-run/react-router/discussions/9841?sort=new).
// but we might want to switch to other patterns in the meantime.
import { FC, useContext, useMemo } from 'react';
import {
Routes,
RoutesProps,
UNSAFE_RouteContext as RouteContext,
} from 'react-router-dom';
export const RootRoutes: FC<RoutesProps> = (props) => {
const ctx = useContext(RouteContext);
const value = useMemo(() => ({ ...ctx, matches: [] }), [ctx]);
return (
<RouteContext.Provider value={value}>
<Routes {...props} />
</RouteContext.Provider>
);
};