@@ -102,6 +102,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
102102 const routeConfigExport = ( await runner . executeFile ( path . join ( process . cwd ( ) , "./app/routes.ts" ) ) ) . default
103103 const routeConfig = await routeConfigExport
104104 routes = routeConfig
105+
105106 const recursiveFlatten = ( routeOrRoutes : Route | Route [ ] ) : Route [ ] => {
106107 if ( Array . isArray ( routeOrRoutes ) ) {
107108 return routeOrRoutes . flatMap ( ( route ) => recursiveFlatten ( route ) )
@@ -111,13 +112,26 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
111112 routeOrRoutes ,
112113 ...recursiveFlatten (
113114 routeOrRoutes . children . map ( ( child ) => {
114- const withoutExtension = child . file . split ( "." ) . slice ( 0 , - 1 ) . join ( "." )
115- const withoutExtensionParent = routeOrRoutes . file . split ( "." ) . slice ( 0 , - 1 ) . join ( "." )
116- // remove the trailing ./ and ../
117- const withoutRelative = withoutExtension . replace ( / ^ \. \/ / , "" ) . replace ( / ^ \. \. \/ / , "" )
115+ // ./path.tsx => path
116+ // ../path.tsx => path
117+ const withoutExtension = child . file
118+ . split ( "." )
119+ . slice ( 0 , - 1 )
120+ . join ( "." )
121+ . replace ( / ^ \. \/ / , "" )
122+ . replace ( / ^ \. \. \/ / , "" )
123+ // ./path.tsx => path
124+ // ../path.tsx => path
125+ const withoutExtensionParent = routeOrRoutes . file
126+ . split ( "." )
127+ . slice ( 0 , - 1 )
128+ . join ( "." )
129+ . replace ( / ^ \. \/ / , "" )
130+ . replace ( / ^ \. \. \/ / , "" )
131+
118132 return {
119133 ...child ,
120- id : child . id ?? withoutRelative ,
134+ id : child . id ?? withoutExtension ,
121135 parentId : withoutExtensionParent ,
122136 }
123137 } )
@@ -128,9 +142,15 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
128142 }
129143 flatRoutes = routes
130144 . map ( ( route ) => {
131- const withoutExtension = route . file . split ( "." ) . slice ( 0 , - 1 ) . join ( "." )
132- const withoutRelative = withoutExtension . replace ( / ^ \. \/ / , "" ) . replace ( / ^ \. \. \/ / , "" )
133- return { ...route , parentId : "root" , id : route . id ?? withoutRelative }
145+ // ./path.tsx => path
146+ // ../path.tsx => path
147+ const withoutExtension = route . file
148+ . split ( "." )
149+ . slice ( 0 , - 1 )
150+ . join ( "." )
151+ . replace ( / ^ \. \/ / , "" )
152+ . replace ( / ^ \. \. \/ / , "" )
153+ return { ...route , parentId : "root" , id : route . id ?? withoutExtension }
134154 } )
135155 . flatMap ( recursiveFlatten )
136156 } catch ( e ) { }
0 commit comments