expressjs 中的 router 问题。
发布于 8 年前 作者 mrlong 3533 次浏览 来自 问答
//当我增加了
router.get('/members/user/info/:userid',function(req,res,next){} )

如userid 为空时,跳到 主页 。 function()是进不去的。能否直接返回end() 我想这个end() 在哪地方写。

7 回复

userid为空的话,应该是找不到匹配的路由,会跳到404那个中间件吧?

怎么跳。 我是直接到 router.get(’/’,function(){});

写在{}里,next的不要! 自豪地采用 CNodeJS ionic

userid为空,应该会去找’/members/user/info/'这个router吧

res.redirect(’/’);

现在这样子的,但不行。

@guosen88100300 你好。 能有例子?? 是不是这样?

router.all(’/’,function(){

//next()  不要这个是吗??

})

回到顶部