Created
September 27, 2022 22:42
-
-
Save matiasfha/89b5228012b559c2ac8ad5eefd9f23ca to your computer and use it in GitHub Desktop.
Routing example
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
/* | |
* App.jsx main entry | |
*/ | |
const SomethingElse = React.lazy(() => import('pages/SomethingElse')); | |
function App() { | |
return ( | |
<BrowserRouter> | |
<Switch> | |
<Route path="/" component={Home} /> | |
<Route path="/somethinElse" component={SomethingElse} /> | |
</Switch> | |
</BrowserRouter> | |
) | |
} | |
/* | |
* SomethingElse.jsx More routes | |
*/ | |
const List = React.lazy(() => import('pages/List')); | |
const Component = React.lazy(() => import('pages/Component')); | |
function SomethingElse() { | |
const { path } = useRouteMatch(); | |
return ( | |
<Switch> | |
<Route path={path} component={List} /> | |
<Route path={`${path}/:id`} component={Component} /> | |
</Switch> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment