<RouterProvider>
declare function RouterProvider(
props: RouterProviderProps
): React.ReactElement;
interface RouterProviderProps {
fallbackElement?: React.ReactNode;
router: Router;
future?: FutureConfig;
}
All data router objects are passed to this component to render your app and enable the rest of the data APIs.
import {
createBrowserRouter,
RouterProvider,
} from "react-router-dom";
const router = createBrowserRouter([
{
path: "/",
element: <Root />,
children: [
{
path: "dashboard",
element: <Dashboard />,
},
{
path: "about",
element: <About />,
},
],
},
]);
ReactDOM.createRoot(document.getElementById("root")).render(
<RouterProvider
router={router}
fallbackElement={<BigSpinner />}
/>
);
fallbackElement
If you are not server rendering your app, createBrowserRouter
will initiate all matching route loaders when it mounts. During this time, you can provide a fallbackElement
to give the user some indication that the app is working. Make that static hosting TTFB count!
<RouterProvider
router={router}
fallbackElement={<SpinnerOfDoom />}
/>
future
An optional set of Future Flags to enable. We recommend opting into newly released future flags sooner rather than later to ease your eventual migration to v7.
function App() {
return (
<RouterProvider
router={router}
future={{ v7_startTransition: true }}
/>
);
}