There are many routing libraries available for React, but Clerk Docs uses React Router as it's the most popular and well-supported routing library for React. If you're using a different routing library, use these guides as a starting point.
React Router supports three different routing strategies, or "modes":
Declarative mode: Enables basic routing features like matching URLs to components, navigating around the app, and providing active states with APIs like <Link>, useNavigate(), and useLocation().
Data mode: Adds data loading, actions, pending states and more with APIs like loader, action, and useFetcher. To use React Router in data mode, see the demo repository. A guide is coming soon.
Framework mode: Use React Router as a framework to build your entire app. To use React Router as a framework instead, see the React Router quickstartReact Router Icon.
This guide will cover how to add React Router in declarative mode, assuming you have followed the React quickstartReact Icon.
Why do we need to move <ClerkProvider /> to its own component?
createRoot(document.getElementById('root')!).render() isn't a component, so you can't use a hook inside of it. In the next step, you'll use the useNavigate() hook with <ClerkProvider>, so you need to move it to its own component.
To use declarative mode, wrap your app in a <BrowserRouter>. To define your app's routes, add <Routes> and <Route> components. This example adds the / (home) route and renders the <App /> component when the URL matches. Read more about routing in the React Router docs.
The useNavigate() hook from react-router is used by Clerk components for navigation events. This will prevent flicker and app reloading.