Describe React Router v4
Differentiate BrowserRouter vs HashRouter
Use Link, Switch, and Route components
import React from 'react';
import ReactDOM from 'react-dom';
import {
BrowserRouter as Router
} from 'react-router-dom';
import App from './App';
ReactDOM.render(
<Router>
<App />
</Router>,
document.getElementById('root')
);
import React, {Component} from 'react';
import {
Switch, Route
} from 'react-router-dom';
const Homepage = () => (<div>HOMEPAGE</div>);
const About = () => (<div>ABOUT</div>);
const SwitchDemo = () => (
<Switch>
<Route path="/about" component={About}/>
<Route path="/" component={Homepage}/>
</Switch>
);
Link
import React from 'react';
import {Link} from 'react-router-dom';
import SwitchDemo from './SwitchDemo';
const App = () => (
<div>
<Link to="/">HOME</Link>
<Link to="/about">ABOUT</Link>
<div style={{fontSize: '3em',
margin: '25px'}}>
<SwitchDemo/>
</div>
</div>
);
NavLink
import React from 'react';
import {NavLink} from 'react-router-dom';
import SwitchDemo from './SwitchDemo';
const s={color: "red"}; //active style
const App = () => (
<div>
<NavLink exact activeStyle={s} to="/">
HOME
</NavLink>
<NavLink exact activeStyle={s} to="/about">
ABOUT
</NavLink>
<div style={{fontSize: '3em',margin: '25px'}}>
<SwitchDemo/>
</div>
</div>
);