Skip to content

Instantly share code, notes, and snippets.

@dschinkel
Created September 25, 2020 01:08
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 dschinkel/1f5c27765d42fb6ac45f03d2c64ab73c to your computer and use it in GitHub Desktop.
Save dschinkel/1f5c27765d42fb6ac45f03d2c64ab73c to your computer and use it in GitHub Desktop.
Using React Router and Hooks Router in the Same App
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