File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -263,14 +263,20 @@ const init = config => {
263
263
}
264
264
}
265
265
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
+
267
269
// Pattern to identify the last path of the route
268
270
// 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)
270
275
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 ( '?' ) )
274
280
item . path = originalPath
275
281
//Create another entry with the optional path
276
282
let optionalItem = { ...item }
You can’t perform that action at this time.
0 commit comments