Skip to content

Instantly share code, notes, and snippets.

@elcodabra
Created September 20, 2017 12:46
Show Gist options
  • Save elcodabra/5495df73acaed9e9493d6a3be62180bc to your computer and use it in GitHub Desktop.
Save elcodabra/5495df73acaed9e9493d6a3be62180bc to your computer and use it in GitHub Desktop.
React Router v4
// ...
import Routes from './routes';
const App = () => {
return (
<div className="container">
<div className="starter-template">
{/* ... */}
<Routes />
</div>
</div>
)
}
export default App;
// ...
import { BrowserRouter, HashRouter } from 'react-router-dom';
ReactDOM.render((
<HashRouter>
<App />
</HashRouter>
), document.getElementById('app-root'));
import React from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';
import About from './components/About';
import Home from './components/Home';
import PageNotFound from './components/PageNotFound';
import ListTweets from './components/ListTweets';
const Routes = () => (
<Switch>
<Redirect exact from='/' to='/tweets'/>
<Route exact path='/home' component={Home}/>
<Route exact path='/about' component={About}/>
<Route path='/tweets' component={ListTweets}/>
<Route component={PageNotFound}/>
</Switch>
)
export default Routes;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment