Skip to content

Instantly share code, notes, and snippets.

@shakdaniel
Created March 30, 2020 19:38
Show Gist options
  • Save shakdaniel/63b58e91632df195c97d429779737ef4 to your computer and use it in GitHub Desktop.
Save shakdaniel/63b58e91632df195c97d429779737ef4 to your computer and use it in GitHub Desktop.
[React Routes] Routes
function App() {
let element = useRoutes([
// These are the same as the props you provide to <Route>
{ path: '/', element: <Home /> },
{ path: 'dashboard', element: <Dashboard /> },
{ path: 'invoices',
element: <Invoices />,
// Nested routes use a children property, which is also
// the same as <Route>
children: [
{ path: ':id', element: <Invoice /> },
{ path: 'sent', element: <SentInvoices /> }
]
},
// Redirects use a redirectTo property to
{ path: 'home', redirectTo: '/' },
// Not found routes work as you'd expect
{ path: '*', element: <NotFound /> }
]);
// The returned element will render the entire element
// hierarchy with all the appropriate context it needs
return element;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment