@@ -14,7 +14,7 @@ export class LegacyRouteConverter {
14
14
* @returns The converted route, or the original route if it cannot be converted.
15
15
*/
16
16
static tryConvert ( route : string ) : string {
17
- // Normalize path to eliminate additional conditions .
17
+ // Normalize path to eliminate additional if statements .
18
18
const routeWithLeadingSlash = route . startsWith ( '/' ) ? route : `/${ route } ` ;
19
19
const normalizedRoute = route . endsWith ( '/' )
20
20
? routeWithLeadingSlash
@@ -27,17 +27,29 @@ export class LegacyRouteConverter {
27
27
}
28
28
return route . replace ( '(.*)' , '{*path}' ) ;
29
29
}
30
+
30
31
if ( normalizedRoute . endsWith ( '/*/' ) ) {
31
32
// Skip printing warning for the "all" wildcard.
32
33
if ( normalizedRoute !== '/*/' ) {
33
34
this . printWarning ( route ) ;
34
35
}
35
36
return route . replace ( '*' , '{*path}' ) ;
36
37
}
38
+
37
39
if ( normalizedRoute . endsWith ( '/+/' ) ) {
38
40
this . printWarning ( route ) ;
39
41
return route . replace ( '/+' , '/*path' ) ;
40
42
}
43
+
44
+ // When route includes any wildcard segments in the middle.
45
+ if ( normalizedRoute . includes ( '/*/' ) ) {
46
+ this . printWarning ( route ) ;
47
+ // Replace each /*/ segment with a named parameter using different name for each segment.
48
+ return route . replaceAll ( '/*/' , ( match , offset ) => {
49
+ return `/*path${ offset } /` ;
50
+ } ) ;
51
+ }
52
+
41
53
return route ;
42
54
}
43
55
@@ -47,7 +59,7 @@ export class LegacyRouteConverter {
47
59
48
60
static printWarning ( route : string ) : void {
49
61
this . logger . warn (
50
- UNSUPPORTED_PATH_MESSAGE `${ route } ` + ' Attempting to convert...' ,
62
+ UNSUPPORTED_PATH_MESSAGE `${ route } ` + ' Attempting to auto- convert...' ,
51
63
) ;
52
64
}
53
65
}
0 commit comments