Created
March 7, 2018 10:31
-
-
Save Gurenax/fc8107e4ef8d6fdde9ae44fb5e111027 to your computer and use it in GitHub Desktop.
React Router Nav Links - Highlighting Active Links
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, { Component } from 'react' | |
import { BrowserRouter as Router, Route, Switch, NavLink } from 'react-router-dom' | |
import './App.css' | |
class App extends Component { | |
render() { | |
return ( | |
<div className="App"> | |
<h1>React Router Nav Links</h1> | |
<Router> | |
<div> | |
<div className="mt-3"> | |
<NavLink className='btn' activeClassName='btn-primary' exact to='/'>Page 1</NavLink> | |
<NavLink className='btn' activeClassName='btn-primary' exact to='/page2'>Page 2</NavLink> | |
<NavLink className='btn' activeClassName='btn-primary' exact to='/page3'>Page 3</NavLink> | |
</div> | |
<div className="mt-3"> | |
<Switch> | |
<Route path='/' | |
exact | |
render={() => ( | |
<h2>Page 1</h2> | |
)} | |
/> | |
<Route path='/page2' | |
exact | |
render={() => ( | |
<h2>Page 2</h2> | |
)} | |
/> | |
<Route path='/page3' | |
exact | |
render={() => ( | |
<h2>Page 3</h2> | |
)} | |
/> | |
</Switch> | |
</div> | |
</div> | |
</Router> | |
</div> | |
) | |
} | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment