Skip to content

Commit 523a69a

Browse files
committed
fixed: regex paths get removed after processing optional paths
1 parent 1c0f5ca commit 523a69a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Router/utils/router.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,20 @@ const init = config => {
263263
}
264264
}
265265
config.routes.forEach(item => {
266-
const path = stripRegex(item.path)
266+
// replacing regexes with 'R' to avoid issues with pattern matching below
267+
const strippedPath = stripRegex(item.path)
268+
267269
// Pattern to identify the last path of the route
268270
// It should start with "/:" + any word and ends with "?"
269-
// Example /player/:asset/:assetId?
271+
// It should be the last path of the route
272+
// valid => /player/:asset/:assetId? (:assetId is optional)
273+
// invalid => /player/:asset/:assetId?/test (:assetId? is not an optional path)
274+
// invalid => /player/:asset?/:assetId? (second path is not considered as an optional path)
270275
const pattern = /.*\/:.*?\?$/u
271-
if (pattern.test(item.path)) {
272-
const optionalPath = path.substring(0, path.lastIndexOf('/'))
273-
const originalPath = path.substring(0, path.lastIndexOf('?'))
276+
277+
if (pattern.test(strippedPath)) {
278+
const optionalPath = item.path.substring(0, item.path.lastIndexOf('/'))
279+
const originalPath = item.path.substring(0, item.path.lastIndexOf('?'))
274280
item.path = originalPath
275281
//Create another entry with the optional path
276282
let optionalItem = { ...item }

0 commit comments

Comments
 (0)