@@ -65,7 +65,7 @@ type Layer = {
6565 route ?: { path : RouteType | RouteType [ ] } ;
6666 path ?: string ;
6767 regexp ?: RegExp ;
68- keys ?: { name : string ; offset : number ; optional : boolean } [ ] ;
68+ keys ?: { name : string | number ; offset : number ; optional : boolean } [ ] ;
6969} ;
7070
7171type RouteType = string | RegExp ;
@@ -433,30 +433,34 @@ export const extractOriginalRoute = (
433433 /**
434434 * iterate param matches from regexp.exec
435435 */
436- paramIndices . forEach ( ( [ startOffset , endOffset ] , index : number ) => {
437- /**
438- * isolate part before param
439- */
440- const substr1 = resultPath . substring ( 0 , startOffset - indexShift ) ;
441- /**
442- * define paramName as replacement in format :pathParam
443- */
444- const replacement = `:${ orderedKeys [ index ] . name } ` ;
445-
446- /**
447- * isolate part after param
448- */
449- const substr2 = resultPath . substring ( endOffset - indexShift ) ;
450-
451- /**
452- * recreate original path but with param replacement
453- */
454- resultPath = substr1 + replacement + substr2 ;
455-
456- /**
457- * calculate new index shift after resultPath was modified
458- */
459- indexShift = indexShift + ( endOffset - startOffset - replacement . length ) ;
436+ paramIndices . forEach ( ( item : [ number , number ] | undefined , index : number ) => {
437+ /** check if offsets is define because in some cases regex d flag returns undefined */
438+ if ( item ) {
439+ const [ startOffset , endOffset ] = item ;
440+ /**
441+ * isolate part before param
442+ */
443+ const substr1 = resultPath . substring ( 0 , startOffset - indexShift ) ;
444+ /**
445+ * define paramName as replacement in format :pathParam
446+ */
447+ const replacement = `:${ orderedKeys [ index ] . name } ` ;
448+
449+ /**
450+ * isolate part after param
451+ */
452+ const substr2 = resultPath . substring ( endOffset - indexShift ) ;
453+
454+ /**
455+ * recreate original path but with param replacement
456+ */
457+ resultPath = substr1 + replacement + substr2 ;
458+
459+ /**
460+ * calculate new index shift after resultPath was modified
461+ */
462+ indexShift = indexShift + ( endOffset - startOffset - replacement . length ) ;
463+ }
460464 } ) ;
461465
462466 return resultPath ;
0 commit comments