Skip to content

Instantly share code, notes, and snippets.

@matiasfha
Created September 27, 2022 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matiasfha/89b5228012b559c2ac8ad5eefd9f23ca to your computer and use it in GitHub Desktop.
Save matiasfha/89b5228012b559c2ac8ad5eefd9f23ca to your computer and use it in GitHub Desktop.
Routing example
/*
* 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