2015-05-25 41 views
0

现在我试图路由到这样的一些可选路径。快速正则表达式路由可选路径

router.get('/foo/bar(.*)', function(req, res, next) { 
    console.log("baz"); 
}); 

为“栏”后接受任何条件,我已经写了这个代码,并对其进行测试,但这并没有工作。哪里不对?

回答

0

你必须尝试这个以下路径模式:

// will match paths starting with /foo/bar and after this any string 
router.get('/foo/bar*', function(req, res, next) { 
    console.log("baz"); 
}); 

它为我工作。查看Express Doc

+0

这非常适用!谢谢!! – yosh

0

尝试细节逃脱.

router.get('/foo/bar(\.*)', function(req, res, next) { 
    console.log("baz"); 
}); 
+0

我试过了,但没有奏效。谢谢你的想法。 – yosh

+0

你能提供一些有效/无效路线的例子吗? – mshaaban