@@ -10,6 +10,7 @@ import ErrorComponent from "./error";
10
10
import LayoutComponent from "./layout" ;
11
11
import NotFoundComponent from "./notFound" ;
12
12
import PageWithLoader from "./pageWithLoader" ;
13
+ import { replaceGroupPaths } from "../utils/helper" ;
13
14
14
15
type Module = { default : React . FC } ;
15
16
const basePath = "/src/app" ;
@@ -38,14 +39,11 @@ const LoadingComponent =
38
39
const recursiveRoutes = (
39
40
routePath : string [ ] ,
40
41
acc : RouteObject [ ] ,
41
- Component : Module ,
42
+ Component : Module
42
43
) => {
43
44
let path = routePath [ 0 ] === "index" ? "/" : routePath [ 0 ] ;
44
45
path = path === "app" ? "/" : path ;
45
- path = path
46
- . replace ( / \: \. \. \. ( \w + ) / , ":$1/*" )
47
- . replace ( / \[ ( .* ) \] / , "$1/*" )
48
- . replace ( / \( .* \) / , "" ) ;
46
+ path = path . replace ( / \: \. \. \. ( \w + ) / , ":$1/*" ) . replace ( / \[ ( .* ) \] / , "$1/*" ) ;
49
47
50
48
let matchedIndex = acc . findIndex ( ( r : RouteObject ) => r . path === path ) ;
51
49
if ( matchedIndex === - 1 ) {
@@ -72,7 +70,7 @@ const recursiveRoutes = (
72
70
recursiveRoutes (
73
71
routePath . slice ( 1 ) ,
74
72
acc [ matchedIndex ] . children as RouteObject [ ] ,
75
- Component ,
73
+ Component
76
74
) ;
77
75
} else {
78
76
const RouterComponent = ( ) => (
@@ -111,7 +109,7 @@ const allRoutes = Object.entries(routes).reduce(
111
109
recursiveRoutes ( routePath , acc , Component ) ;
112
110
return acc ;
113
111
} ,
114
- [ ] ,
112
+ [ ]
115
113
) ;
116
114
117
115
const catchAllRoute = {
@@ -129,7 +127,7 @@ export const useAppRouter = () => {
129
127
}
130
128
}
131
129
} ) ;
132
- return allRoutes satisfies RouteObject [ ] ;
130
+ return replaceGroupPaths ( allRoutes ) satisfies RouteObject [ ] ;
133
131
} ;
134
132
135
133
export const AppRouter = ( { router = createBrowserRouter } ) => {
0 commit comments