运行 serve -l ./build 构建 react-app 后出现 404 错误

Getting 404 error after running serve -l ./build after building react-app

当我尝试 运行 这个命令时出现 404 错误

serve -l build

构建 React 应用程序后,这是我的 ./app.js 和在文件中实现的 react-router。

import React from "react";
import Header from "./Components/Header";
import LeafletContainer from "./container/LeafletContainer";
import SignUp from "./Components/SignUp";
import Profile from "./Components/Profile";
import SavedLocations from "./Components/SavedLocations";
import Swiper from "./Components/swiper";

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

const Slash = () => {
  return (
    <>
      <Header />
      <LeafletContainer />
      <Swiper />
    </>
  );
};

function App() {
  return (
    <div className="wrapper">
      <Router>
        <Switch>
          <Route exact path="/" component={Slash} />
          <Route exact path="/signup" component={SignUp} />
          <Route exact path="/profile" component={Profile} />
          <Route exact path="/locations" component={SavedLocations} />
        </Switch>
      </Router>
    </div>
  );
}

export default App;

而且我在 ./package.json

中定义了这一行
{
...,
    "homepage": "."
...,
}

使用 -l 标志,您应该提供一个 endpoint/ports 来监听。我想你应该在你的情况下使用 -s 标志:

serve -s build

或者您可以像这样将端口添加到您的命令中:

serve -l 3232 build

然后你可以在 localhost:3232

上找到你的应用