且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 React-router 复制/粘贴路由并获得“正确"页面?

更新时间:2023-12-01 19:53:28

由于您不进行任何服务器端渲染,因此不需要在服务器上进行路由.你只需要配置一个回退,例如这样:

Since you are not doing any serverside rendering, you don't need routing on the server. You only need to configure a fallback, for example like this:

import fallback from 'express-history-api-fallback';
import express from 'express';
import http from 'http';

// Set up express
const app = express();
const server = http.createServer(app);
const root = `${__dirname}`;

// History Fallback for express
app.use(express.static(root));
app.use(fallback('index.html', { root }));

// Listen
server.listen(8080, '0.0.0.0');