@@ -10,6 +10,7 @@ import ErrorComponent from "./error";
1010import LayoutComponent from "./layout" ;
1111import NotFoundComponent from "./notFound" ;
1212import PageWithLoader from "./pageWithLoader" ;
13+ import { replaceGroupPaths } from "../utils/helper" ;
1314
1415type Module = { default : React . FC } ;
1516const basePath = "/src/app" ;
@@ -38,14 +39,11 @@ const LoadingComponent =
3839const recursiveRoutes = (
3940 routePath : string [ ] ,
4041 acc : RouteObject [ ] ,
41- Component : Module ,
42+ Component : Module
4243) => {
4344 let path = routePath [ 0 ] === "index" ? "/" : routePath [ 0 ] ;
4445 path = path === "app" ? "/" : path ;
45- path = path
46- . replace ( / \: \. \. \. ( \w + ) / , ":$1/*" )
47- . replace ( / \[ ( .* ) \] / , "$1/*" )
48- . replace ( / \( .* \) / , "" ) ;
46+ path = path . replace ( / \: \. \. \. ( \w + ) / , ":$1/*" ) . replace ( / \[ ( .* ) \] / , "$1/*" ) ;
4947
5048 let matchedIndex = acc . findIndex ( ( r : RouteObject ) => r . path === path ) ;
5149 if ( matchedIndex === - 1 ) {
@@ -72,7 +70,7 @@ const recursiveRoutes = (
7270 recursiveRoutes (
7371 routePath . slice ( 1 ) ,
7472 acc [ matchedIndex ] . children as RouteObject [ ] ,
75- Component ,
73+ Component
7674 ) ;
7775 } else {
7876 const RouterComponent = ( ) => (
@@ -111,7 +109,7 @@ const allRoutes = Object.entries(routes).reduce(
111109 recursiveRoutes ( routePath , acc , Component ) ;
112110 return acc ;
113111 } ,
114- [ ] ,
112+ [ ]
115113) ;
116114
117115const catchAllRoute = {
@@ -129,7 +127,7 @@ export const useAppRouter = () => {
129127 }
130128 }
131129 } ) ;
132- return allRoutes satisfies RouteObject [ ] ;
130+ return replaceGroupPaths ( allRoutes ) satisfies RouteObject [ ] ;
133131} ;
134132
135133export const AppRouter = ( { router = createBrowserRouter } ) => {
0 commit comments