安装
demo1
import { BrowserRouter as Router, Route, Link } from "react-router-dom"
const Index = () => <h2>Home</h2>;
const About = () => <h2>About</h2>;
const Users = () => <h2>Users</h2>
const Header= ()=><div className="nav">
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/about/">About</Link>
</li>
<li>
<Link to="/users/">Users</Link>
</li>
</ul>
</div>
class App extends Component {
render() {
return (
<Router>
<div>
<Header />
<div className="container">
<Route path="/" exact component={Index} />
<Route path="/about/" component={About} />
<Route path="/users/" component={Users} />
</div>
</div>
</Router>
);
}
demo2
在这里插入代码片