我开始使用react-router v4。<Router>
我的app.js中有一个简单的导航链接(请参见下面的代码)。如果我导航到localhost/vocabulary
,路由器会将我重定向到正确的页面。但是,当我在之后按重新加载(F5)(localhost/vocabulary
)时,所有内容消失并且浏览器报告Cannot GET /vocabulary
。那怎么可能?有人可以给我任何解决方法的提示(正确重新加载页面)吗?
App.js:
import React from 'react'
import ReactDOM from 'react-dom'
import { BrowserRouter as Router, Route, Link } from 'react-router-dom'
import { Switch, Redirect } from 'react-router'
import Login from './pages/Login'
import Vocabulary from './pages/Vocabulary'
const appContainer = document.getElementById('app')
ReactDOM.render(
<Router>
<div>
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to="/vocabulary">Vocabulary</Link></li>
</ul>
<Switch>
<Route exact path="/" component={Login} />
<Route exact path="/vocabulary" component={Vocabulary} />
</Switch>
</div>
</Router>,
appContainer)