Created
September 20, 2017 12:46
-
-
Save elcodabra/5495df73acaed9e9493d6a3be62180bc to your computer and use it in GitHub Desktop.
React Router v4
This file contains 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 Routes from './routes'; | |
const App = () => { | |
return ( | |
<div className="container"> | |
<div className="starter-template"> | |
{/* ... */} | |
<Routes /> | |
</div> | |
</div> | |
) | |
} | |
export default App; |
This file contains 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 { BrowserRouter, HashRouter } from 'react-router-dom'; | |
ReactDOM.render(( | |
<HashRouter> | |
<App /> | |
</HashRouter> | |
), document.getElementById('app-root')); |
This file contains 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 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