Index route in React Router

| Tag react  router 

An index route can be thought of as a default child route. In React Router, if no children match a parent route, it will display an index route if one is defined. An index route has no path and instead has a index boolean property:

const router = createBrowserRouter([
    {
        path: '/',
        element: <App />,
        errorElement: <ErrorPage />,
        children: [
            {index: true, element: <HomePage />},
            {path: 'products', element: <ProductsPage />},
            {path: 'products/:id', element: <ProductPage />}
        ]
    },
]);

Prev     Next