【发布时间】:2021-03-15 09:11:46
【问题描述】:
当我尝试运行此命令时出现 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": "."
...,
}
【问题讨论】:
-
你试过空字符串
homepage吗?还是完全删除?请改用serve build。 -
serve -l ./build应该做什么? -
你为什么首先使用
--listen标志? -
@ChrisG 我已使用此推荐
bash serve -s build解决了问题,感谢您的帮助
标签: javascript reactjs react-router react-router-dom serve