节点 res.render 更改视图但不更改 url [英] node res.render changes view but not url
本文介绍了节点 res.render 更改视图但不更改 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从 jade view
发送一个 id
到它的 controller
(后端),然后控制器查询 mongodb
并将结果发送到新的 jade view
-angular
.结果 &视图出现但 URL
保持不变(前一个视图),因此如果我 F5
当前视图,它会重新加载前一个视图.
所以路由是:view->node->angular
想法?
I am sending an id
from a jade view
to its controller
(backend), the controller then queries mongodb
and the result is sent to a new jade view
-angular
.
The results & view appear but URL
stays the same (previous view), thus if I F5
the current view, it reloads the previous view.
So the route is: view->node->angular
Ideas?
翡翠发射器视图
form(method="post")
input(type="hidden" name="id" value=cart._id)
input(type='hidden', name='_csrf', value=_csrf)
button.btn.product.btn-primary(type='submit', id=cart._id class='')
控制器
exports.pushCart = (req, res) => {
if (passport.isAuthenticated) {
Order.findOne({ _id: req.body.id})
.select('-_id productOrder')
.exec(function (err, orderObj) {
if(!err) {
var productOrder = orderObj.productOrder;
res.render('store/cart', {
title: 'MyCart',
angularApp: 'storeApp',
products: productOrder
});
}
});
} else {
res.redirect('/login');
}
};
推荐答案
如果要更改 URL,则需要重定向像这样
You need to redirect ,if you want the URL to change like this
res.redirect('/some/path')
这篇关于节点 res.render 更改视图但不更改 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文