I have a little bit problem with the routes of node.js . I managed these routes(get and post) in the folder called routes. Now I'd like to call from one route an other route in a different file . How can I do?
我对node.js的路由有点问题。我在名为routes的文件夹中管理这些路由(get和post)。现在我想从一个路由呼叫另一个路径在另一个文件中。我能怎么做?
1 个解决方案
#1
2
Using res.redirect you can move to another route.
here is an Example code
使用res.redirect,您可以移动到另一个路线。这是一个示例代码
router.get('/abc', function(req, res){
....
res.redirect('/efg');
}
and in your app.js define file path for the route like
并在您的app.js中定义路径的文件路径
var efg= require('./path-to-efg');
app.use('/', efg);
#1
2
Using res.redirect you can move to another route.
here is an Example code
使用res.redirect,您可以移动到另一个路线。这是一个示例代码
router.get('/abc', function(req, res){
....
res.redirect('/efg');
}
and in your app.js define file path for the route like
并在您的app.js中定义路径的文件路径
var efg= require('./path-to-efg');
app.use('/', efg);