使用快速路由显示React页面

问题描述 投票:0回答:2

所以我试图将我的React App连接到快速路由-到目前为止,对于我的服务器,我有

const express = require('express');
const app = express();
const port = 5000;

app.use('/test', require('./client/src/App'));

app.listen(port, () => console.log(`Server started on port ${port}`));

我希望能够转到localhost:5000 / test并显示我的create-react-app(./client/src/App)。

我的服务器在5000上运行,而React在3000上运行。

我意识到React有自己的路由,但是我想知道是否可以通过这种方式。

javascript reactjs express routing
2个回答
0
投票

这是行不通的。 Express.js不知道类似react的情况。您需要不使用react来处理react-router应用程序的路由。

[Express.js仅负责创建在express而不是react中的端点。


0
投票

如果要使用这样的快速路由,则可能只能使用react构建而不是react源来进行。

否则,如果要使用React开发环境(假设运行在localhost:3000上,则应该能够在expressnginx上使用反向代理。

© www.soinside.com 2019 - 2024. All rights reserved.