与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); });
- 如何设置RedisStore – Node,Express,Socket.io,Heroku
- 无法通过express项目连接到mongodb
- 使用socket.io和express-session时,会在每次页面加载时生成一个新的会话ID
- 保存第一次login历史logging后,ExpressJS应用login失败
- Node.js Body-Parser无法检索表单input
- azure node.js console.log不能login到stdout或stderr文件
- NodeJS Express – 显示URL而不使用html扩展
- Passport-jwt令牌过期
- 如何从nodejs / express向浏览器发送成功状态?