[英]Calling router.get using a redirect in Express
Is there a way to specifically call a router.get(...)
function in Express? 有没有一种方法可以在Express中专门调用
router.get(...)
函数?
Suppose I have a router.get('/my-route', function(req, res) { ... });
假设我有一个
router.get('/my-route', function(req, res) { ... });
, is it possible then, in some other area of my code, to call res.redirect('my-route');
,那么是否有可能在我的代码的其他区域调用
res.redirect('my-route');
and expect it to be caught by the router? 并期望它会被路由器捕获?
Thanks 谢谢
Routes define functions to be executed following an HTTP Request. 路由定义了要在HTTP请求之后执行的功能。 If you want to executed some route defined as
router.get(...)
you need to call res.redirect()
with an actual route like: 如果要执行一些定义为
router.get(...)
路由, router.get(...)
需要使用实际路由来调用res.redirect()
,例如:
res.redirect('/some/path');
That should execute the function defined in: 那应该执行以下函数中定义的函数:
app.use('/some/path', someFunction);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.