反应:刷新页面后获取404

时间:2020-11-12 11:40:26

标签: reactjs react-router http-status-code-404 windows-server

(我正在使用React和React Router的最新版本,截至2020年11月12日。不确定版本号是什么。)

这是我的App.js(减去进口额)。

const App = () => {
  return (
    <Router basename={'/dev'}>
      <Switch>
            <Route path="/about">
              <AboutPage />
            </Route>
            <Route path="/users">
              <UserListPage />
            </Route>
            <Route path="/events">
              <EventListPage />
            </Route>
            <Route path="/dashboard">
              <Dashboard />
            </Route>
            <Route exact path="/">
              <Redirect to="/dashboard" />
            </Route>
          </Switch>
    </Router>
  );
};

我试图将它们部署到根目录下的子文件夹'dev'中。因此,假设服务器名称为hostname,我正在尝试将我的应用设置为http://hostname/dev。这在大多数情况下都有效,包括基于链接的导航。问题是,每当我尝试手动刷新路由器呈现的页面,例如http://hostname/dev/events时,都会收到404消息。如果我打开一个新的浏览器选项卡,在其中键入URL并按Enter,也会发生同样的事情。我应该注意,在本地(从http://localhost:3000运行)时不会发生此问题。我知道BrowserRouter可能需要一些服务器端自定义,但是不知道它们是什么。这里可能出什么问题了?我在Windows服务器上使用WAMP。

0 个答案:

没有答案