Skip to content

Instantly share code, notes, and snippets.

@cbh6
Last active August 11, 2019 05:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbh6/47c337fa865729268bc535c905820544 to your computer and use it in GitHub Desktop.
Save cbh6/47c337fa865729268bc535c905820544 to your computer and use it in GitHub Desktop.
// you can define router
// and add a switch with all routes as a child of a "Main layout component" called app
import React from 'react';
import { render } from 'react-dom';
import createHistory from 'history/createBrowserHistory';
import { Router, Route, Redirect, Switch } from 'react-router-dom';
const history = createHistory();
const routes = (
<Router history={history}>
<App>
<Switch>
<Route exact path="/" component={Home} />
<Route exact path="/post" component={PostList} />
<Route path="/showpost/:slug" component={ShowPost} />
<Route path="/page/:slug" component={ShowPage} />
<Route path="/login" component={Login} />
<Route path="/register" component={Register} />
<Route path="/forgotpassword" component={Forgot} />
<Route path="/password/reset/:token" component={Reset} />
<Route path="/logout" component={Logout} />
<Route path="/user" component={User} />
<Route path="/saveorder" render={()=><SaveOrder data={this.state.data}/>} />
</Switch>
</App>
</Router>
);
// and then in your app.js component
const App = props => (
<div>
<Header />
<Menu />
<div>
{props.children}
</div>
</div>
);
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment