reactjs 运行npm run build后,HashRouter未按预期运行

t98cgbkg  于 2022-12-26  发布在  React
关注(0)|答案(1)|浏览(144)

我正在开发一个带有reactjs的应用程序
我运行了npm run build,并将build文件夹的内容移动到xampp服务器
404 Not Found错误提示页面未找到
我将路由从BrowserHistory更改为HashRouter
但问题依然存在。
index.js

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { Provider } from "react-redux";
import { persistor, store } from "./noautharea/redux/store";
import { PersistGate } from "redux-persist/integration/react";
import { HashRouter as Router } from "react-router-dom";

ReactDOM.render(
 <Provider store={store}>
   <Router>
     <PersistGate loading={null} persistor={persistor}>
        <App />
     </PersistGate>
   </Router>
 </Provider>,
 document.getElementById("root")
);
reportWebVitals();

App.js

function App() {
  const receptionist = "receptionist";
  return (
    <div className="App">
      <Routes>
        <Route path="/manager/login" element={<Manager />} />
        <Route path="/receptionist/login" element={<Receptionist />} />
        <Route path="/" exact element={<Receptionist />} />
     </Routes>
   </div>
  )
 }

brqmpdu1

brqmpdu11#

尝试将App.js更改为:

function App() {
  const receptionist = "receptionist";
  return (
    <div className="App">
      <Routes>
        <Route path="/#/manager/login" element={<Manager />} />
        <Route path="/#/receptionist/login" element={<Receptionist />} />
        <Route path="/#/" exact element={<Receptionist />} />
     </Routes>
   </div>
  )
 }

我认为问题是HashRouter将在“/#/”上呈现,而不是在“/”上呈现

相关问题