Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

useRoutes

// React Router v6:
// hook functionally equivalent to <Routes>, but uses JS objects instead
// of <Route>, use this hook instead of 'react-router-config' (React Router v5)
import { useRoutes } from 'react-router-dom';

function App() {
  let element = useRoutes([
    {
      path: '/',
      element: <Dash />,
      children: [
        { path: 'messages', element: <DashMessages /> },
        { path: 'tasks', element: <DashTasks /> }
      ]
    },
    { path: 'team', element: <About /> }
  ]);

  return element;
}
Source by reactrouter.com #
 
PREVIOUS NEXT
Tagged: #useRoutes
ADD COMMENT
Topic
Name
9+5 =