简体   繁体   中英

Calling router.get using a redirect in Express

Is there a way to specifically call a router.get(...) function in Express?

Suppose I have a router.get('/my-route', function(req, res) { ... }); , is it possible then, in some other area of my code, to call res.redirect('my-route'); and expect it to be caught by the router?

Thanks

Routes define functions to be executed following an HTTP Request. If you want to executed some route defined as router.get(...) you need to call res.redirect() with an actual route like:

res.redirect('/some/path');

That should execute the function defined in:

app.use('/some/path', someFunction);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM