現在我試圖路由到這樣的一些可選路徑。快速正則表達式路由可選路徑
router.get('/foo/bar(.*)', function(req, res, next) {
console.log("baz");
});
爲「欄」後接受任何條件,我已經寫了這個代碼,並對其進行測試,但這並沒有工作。哪裏不對?
現在我試圖路由到這樣的一些可選路徑。快速正則表達式路由可選路徑
router.get('/foo/bar(.*)', function(req, res, next) {
console.log("baz");
});
爲「欄」後接受任何條件,我已經寫了這個代碼,並對其進行測試,但這並沒有工作。哪裏不對?
你必須嘗試這個以下路徑模式:
// 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
這非常適用!謝謝!! – yosh