安装Router
npm install --save react-router react-router-dom
import {
Route, Link} from 'react-router-dom';
App.js
import React, {
Component } from 'react';
import {
BrowserRouter } from 'react-router-dom';
import Blog from './containers/Blog/Blog';
class App extends Component {
render() {
return (
<BrowserRouter basename='/'>
<div className="App">
<Blog />
</div>
</BrowserRouter>
);
}
}
export default App;
为页面添加两个a link
<header className="Blog">
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/new-post">New</a