[英]vue-router path-to-regexp does not match optional route path parameter group
[英]How to match an optional segment in vue-router with path-to-regexp
Vue-Router使用https://github.com/pillarjs/path-to-regexp將路徑轉換為正則表達式。
我一直在嘗試創建一個與路徑中的可選段匹配的表達式,但是沒有成功。
我一直在使用http://forbeslindesay.github.io/express-route-tester/軟件包版本0.1.7進行測試。
路徑應如下所示:
/:必填參數/(identifier /:parameter1 /:parameter2)?/ *應該始終需要第一個參數。 如果第一個參數與單詞“ identifier”作為表達式的第二部分匹配,則parameter1和parameter2必須為兩個。 如果不是,則不能使用兩個參數,並且*應該匹配。
我試過的
/:必需/(標識符/:可選1 /:可選2)?/ *路由
/ required / identifier / optional1 / optional2 / bla應該等於
/必需/ bla
我的猜測是您正在嘗試編寫一些表達式,如下所示:
(/required/)(?:identifier/optional1/optional2/)(.*)
並替換為$1$2
。
如果您想瀏覽/簡化/修改該表達式,請在regex101.com的右上方面板中進行說明 。 如果願意,您還可以在此鏈接中觀看,它將如何與某些示例輸入匹配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.