Created
March 30, 2020 19:38
-
-
Save shakdaniel/63b58e91632df195c97d429779737ef4 to your computer and use it in GitHub Desktop.
[React Routes] Routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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