与express.js路由设置反应的应用程序

我正在使用angular.js,我在express.js中这样做

app.get("*", function (req, res) { res.redirect('/#' + req.originalUrl) }) 

这样浏览器将会使用angular度而不是快速的路由。 但如何与反应路由器做到这一点? 我有2个文件夹,命名服务器和客户端,服务器文件夹有快递和API逻辑,而客户端文件夹只是一个反应的应用程序。

您需要将要呈现您的应用的HTML文件的path放入

 app.get("/",(res,res) => { res.sendFile('put the path of the html file you are rendering your app into here'); } 

这里是一个快速server.js与反应工作的例子

 var express = require('express'); var bodyParser = require('body-parser'); var logger = require('morgan'); var app = express(); var PORT = process.env.PORT || 3000; app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended:true})); app.use(bodyParser.text()); app.use(bodyParser.json({type: 'application/vnd.api+json'})); app.use(express.static('./public')); app.get('/', function(req,res){ res.sendFile('./public/index.html'); }); app.listen(PORT, function(){ console.log("Listening on port: " + PORT); });