如果我使用react-router导航到除主页URL之外的任何URL,则会出现404错误

时间:2018-03-16 19:08:12

标签: reactjs redux react-router react-redux react-router-v4

我的routes.js为

import {
  BrowserRouter as Router,
  Route
} from 'react-router-dom';

  <Router>
    <div>
      <Route exact path="/" component={login}/>
      <Route path="/calculator" component={calculatorPage}/>
      <Route path="/result" component={resultPage}/>
    </div>
  </Router>

我已经在服务器上提升了应用程序,当我尝试使用/ calculator输入URL时,我收到404错误。如果我使用主页URL,到计算器页面,它工作正常。如果我直接进入,那么我得到404错误。

在我当地一切正常。即使我直接输入/计算器,我也会得到页面。

1 个答案:

答案 0 :(得分:0)

<强>的.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteBase /<YOUR_BASE_URL_HERE>/
RewriteRule ^(.*) index.html [NC,L]