@@ -61,12 +61,10 @@ async function getRouteNodes(config: Config) {
61
61
if ( stat . isDirectory ( ) ) {
62
62
await recurse ( relativePath )
63
63
} else {
64
- const filePath = path . join ( dir , fileName )
64
+ const filePath = replaceBackslash ( path . join ( dir , fileName ) )
65
65
const filePathNoExt = removeExt ( filePath )
66
66
let routePath =
67
- replaceBackslash (
68
- cleanPath ( `/${ filePathNoExt . split ( '.' ) . join ( '/' ) } ` ) ,
69
- ) ?? ''
67
+ cleanPath ( `/${ filePathNoExt . split ( '.' ) . join ( '/' ) } ` ) || ''
70
68
const variableName = routePathToVariable ( routePath )
71
69
72
70
// Remove the index from the route path and
@@ -149,26 +147,20 @@ export async function generator(config: Config) {
149
147
const start = Date . now ( )
150
148
const routePathIdPrefix = config . routeFilePrefix ?? ''
151
149
152
- let preRouteNodes = await getRouteNodes ( config )
153
-
154
- const sortRouteNodes = ( nodes : RouteNode [ ] ) : RouteNode [ ] => {
155
- return multiSortBy ( nodes , [
156
- ( d ) => ( d . routePath === '/' ? - 1 : 1 ) ,
157
- ( d ) => d . routePath ?. split ( '/' ) . length ,
158
- ( d ) => ( d . filePath ?. match ( / [ . / ] i n d e x [ . ] / ) ? 1 : - 1 ) ,
159
- ( d ) =>
160
- d . filePath ?. match (
161
- / [ . / ] ( c o m p o n e n t | e r r o r C o m p o n e n t | p e n d i n g C o m p o n e n t | l o a d e r ) [ . ] / ,
162
- )
163
- ? 1
164
- : - 1 ,
165
- ( d ) => ( d . filePath ?. match ( / [ . / ] r o u t e [ . ] / ) ? - 1 : 1 ) ,
166
- ( d ) => ( d . routePath ?. endsWith ( '/' ) ? - 1 : 1 ) ,
167
- ( d ) => d . routePath ,
168
- ] ) . filter ( ( d ) => d . routePath !== `/${ routePathIdPrefix + rootPathId } ` )
169
- }
170
-
171
- preRouteNodes = sortRouteNodes ( preRouteNodes )
150
+ const preRouteNodes = multiSortBy ( await getRouteNodes ( config ) , [
151
+ ( d ) => ( d . routePath === '/' ? - 1 : 1 ) ,
152
+ ( d ) => d . routePath ?. split ( '/' ) . length ,
153
+ ( d ) => ( d . filePath ?. match ( / [ . / ] i n d e x [ . ] / ) ? 1 : - 1 ) ,
154
+ ( d ) =>
155
+ d . filePath ?. match (
156
+ / [ . / ] ( c o m p o n e n t | e r r o r C o m p o n e n t | p e n d i n g C o m p o n e n t | l o a d e r ) [ . ] / ,
157
+ )
158
+ ? 1
159
+ : - 1 ,
160
+ ( d ) => ( d . filePath ?. match ( / [ . / ] r o u t e [ . ] / ) ? - 1 : 1 ) ,
161
+ ( d ) => ( d . routePath ?. endsWith ( '/' ) ? - 1 : 1 ) ,
162
+ ( d ) => d . routePath ,
163
+ ] ) . filter ( ( d ) => d . routePath !== `/${ routePathIdPrefix + rootPathId } ` )
172
164
173
165
const routeTree : RouteNode [ ] = [ ]
174
166
const routePiecesByPath : Record < string , RouteSubNode > = { }
@@ -518,8 +510,8 @@ function capitalize(s: string) {
518
510
return s . charAt ( 0 ) . toUpperCase ( ) + s . slice ( 1 )
519
511
}
520
512
521
- function sanitize ( s ? : string ) {
522
- return replaceBackslash ( s ? .replace ( / \\ i n d e x / gi, '' ) )
513
+ function sanitize ( s : string ) {
514
+ return replaceBackslash ( s . replace ( / \\ i n d e x / gi, '' ) )
523
515
}
524
516
525
517
function removeUnderscores ( s ?: string ) {
@@ -530,8 +522,8 @@ function removeTrailingUnderscores(s?: string) {
530
522
return s ?. replace ( / ( _ $ ) / , '' ) . replace ( / ( _ \/ ) / , '/' )
531
523
}
532
524
533
- function replaceBackslash ( s ? : string ) {
534
- return s ? .replace ( / \\ / gi, '/' )
525
+ function replaceBackslash ( s : string ) {
526
+ return s . replace ( / \\ / gi, '/' )
535
527
}
536
528
537
529
export function hasParentRoute (
0 commit comments