Tôi bắt đầu sử dụng bộ phản ứng-bộ định tuyến v4. Tôi có một đơn giản <Router>
trong app.js của tôi với một số liên kết điều hướng (xem mã bên dưới). Nếu tôi điều hướng đến localhost/vocabulary
, bộ định tuyến sẽ chuyển hướng tôi đến đúng trang. Tuy nhiên, khi tôi nhấn lại (F5) sau đó (localhost/vocabulary
), tất cả nội dung sẽ biến mất và báo cáo trình duyệt Cannot GET /vocabulary
. Làm thế nào là có thể? Ai đó có thể cho tôi bất kỳ đầu mối làm thế nào để giải quyết điều đó (tải lại trang một cách chính xác)?React-router v4 - không thể GET * url *
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)
có thể trùng lặp của [Phản ứng-router url không hoạt động khi làm mới hoặc writting bằng tay] (http://stackoverflow.com/questions/27928372/ phản ứng-router-urls-không-làm việc-khi-làm mới-hoặc-writting-bằng tay) – Chris