<Router>
<Switch>
{console.log("Loading Routes")}
<Route path="/booking" component={Booking} />
<Route path="/bookings" component={Bookings} />
<Route path="/admin/login" component={AdminLogin} />
<Route path="/admin/panel" component={AdminPanel} />
<Route path="/admin/new" component={AddPhone} />
<Route path="/admin/list" component={PhoneList} />
<Route path="/admin/edit/:id" component={EditPhone} />
<Route exact path="/" component={Home} />
<Redirect to="/" />
</Switch>
</Router>
app.use(express.static("./client/build"));
// Routes for the Application
app.use("/auth", require("./routes/auth"));
app.use("/api", require("./routes/api"));
app.use("/api/booking", require("./routes/booking"));
app.get("/*", (req, res) => {
console.log(1);
res.setHeader("Content-type", "text/html");
res.sendFile(path.join(__dirname, "client/build/index.html"));
});
app.get("/*/*", (req, res) => {
console.log(1);
res.setHeader("Content-type", "text/html");
res.sendFile(path.join(__dirname, "client/build/index.html"));
});
app.listen(PORT, () => {
console.log("Listening to PORT : ", PORT);
});
我使用上面的代码来服务它,在构建时一切都运行良好,但是当我用我的服务器服务文件时,默认的/ route运行得很好,但是/admin/login路由或任何其他路由加载一个空白页面。
1条答案
按热度按时间nwo49xxi1#
您的服务器根目录是否包含.htaccess文件?
如果没有,创建.htaccess文件,并在其中: