如何在不重定向vanilla Express中的URL的情况下将用户重定向到其他路由?例如,如果我有路线
express = require('express');
app = express();
app.route('/old').get(function(req, res, next) {
res.redirect('/new');
});
app.route('/new').get(function(req, res, next) {
res.send('This is the new route');
});
app.listen(3000);
Run Code Online (Sandbox Code Playgroud)
我指向我的浏览器http://localhost:3000/old,应用程序成功重定向,页面显示This is the new route,但URL也已更改为http://localhost:3000/new.如何让应用程序重定向到new路由但保留旧URL(http://localhost:3000/old)?
我很好安装另一个中间件(好像我还没有已经有一百万个),但理想情况下,我想在没有额外中间件的情况下这样做.另外,我在Express.js中完全这样做,没有PHP,nginx或其他任何东西.我将在我的应用程序中使用Angular.js,但这似乎更像是服务器端行为,而不是客户端行为.我有时会在客户端重定向,但我不想一直这样做.
Ian*_*ang 11
而不是重定向,如何使用请求模块发送获取请求
并进行回调以更新内容.
var request = require('request');
app.route('/old').get(function(req, res, next) {
request.get('/new', function(err, response, body) {
if (!err) {
req.send(body);
}
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3641 次 |
| 最近记录: |