Hook version of <Routes> that uses objects instead of components. These objects have the same properties as the component props.
<Routes>
The return value of useRoutes is either a valid React element you can use to render the route tree, or null if nothing matched.
useRoutes
null
import * as React from "react";import { useRoutes } from "react-router";function App() { let element = useRoutes([ { path: "/", element: <Dashboard />, children: [ { path: "messages", element: <DashboardMessages />, }, { path: "tasks", element: <DashboardTasks /> }, ], }, { path: "team", element: <AboutPage /> }, ]); return element;} Copy
import * as React from "react";import { useRoutes } from "react-router";function App() { let element = useRoutes([ { path: "/", element: <Dashboard />, children: [ { path: "messages", element: <DashboardMessages />, }, { path: "tasks", element: <DashboardTasks /> }, ], }, { path: "team", element: <AboutPage /> }, ]); return element;}
Optional
Hook version of
<Routes>
that uses objects instead of components. These objects have the same properties as the component props.The return value of
useRoutes
is either a valid React element you can use to render the route tree, ornull
if nothing matched.