2015-05-25 38 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