Skip to content

Commit c56923a

Browse files
committed
Updated code as per the comments
1 parent f30cdfe commit c56923a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Router/utils/router.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,17 @@ const init = config => {
263263
}
264264
}
265265
config.routes.forEach(item => {
266-
const path = item.path
267-
if (path.lastIndexOf('?') !== -1) {
266+
let path = item.path
267+
// Pattern to identify the last path of the route
268+
// It should start with "/:" + any word and ends with "?"
269+
// Example /player/:asset/:assetId?
270+
const pattern = /\/:{1}\w+\?$/
271+
if (pattern.test(item.path)) {
268272
const optionalPath = path.substring(0, path.lastIndexOf('/'))
269-
item.path = path.substring(0, path.lastIndexOf('?'))
273+
const originalPath = path.substring(0, path.lastIndexOf('?'))
274+
item.path = originalPath
270275
//Create another entry with the optional path
271-
const optionalItem = { ...item }
276+
let optionalItem = { ...item }
272277
optionalItem.path = optionalPath
273278
config.routes.push(optionalItem)
274279
}

0 commit comments

Comments
 (0)