🍃 Leaf

React Router

Installation

npm i react-router-dom@latest

Usage

// index.jsx e.g.:
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import { createRoot } from 'react-dom/client';
import { StrictMode } from 'react';
import App from './App';

const router = createBrowserRouter([
  {
    path: '/',
    element: <div>Root element</div>,
    errorElement: <div>404 Error</div>
  }
]);

createRoot(document.getElementById('root')).render(
  <StrictMode>
    <RouterProvider {...{ router }} />
  </StrictMode>
);

Common components:

Common hooks:


Reference: React Router (reactrouter.com).