Created
September 25, 2020 01:08
-
-
Save dschinkel/1f5c27765d42fb6ac45f03d2c64ab73c to your computer and use it in GitHub Desktop.
Using React Router and Hooks Router in the Same App
This file contains hidden or 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
import React, { Component } from 'react'; | |
import { Route, Switch } from 'react-router-dom'; | |
... | |
import { useRoutes } from 'hookrouter'; | |
export const routes = { | |
'/login': () => <Login /> | |
}; | |
const RenderRoutes = () => { | |
const routeResult = useRoutes(routes); | |
return ( | |
<>{routeResult}</> | |
); | |
}; | |
class Container extends Component { | |
render() { | |
return (<div>{this.props.children}</div>); | |
} | |
} | |
const App = () => ( | |
<> | |
<Switch> | |
<Route component={withTracker(HomePageContainer)} exact path="/" /> | |
<Route component={Build} exact path="/build" /> | |
<Route | |
component={withTracker(CompanyDetailContainer)} | |
name="companydetail" | |
path="/companies/:companyId/details" /> | |
<Route component={withTracker(InterviewContainer)} name="company" path="/interviews/companies/:companyId" /> | |
<Route component={withTracker(About)} name="about" path="/about" /> | |
<Route component={withTracker(Container)} path="/" /> | |
<Route component={withTracker(NotFound)} path="*" /> | |
</Switch> | |
<RenderRoutes /> | |
</> | |
); | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment