Skip to content

Commit 54d5258

Browse files
fix(router-generator): use cleanPath for virtual-physical subtree variable names and paths
Agent-Logs-Url: https://github.com/TanStack/router/sessions/df80fd7e-87ea-4f4d-ac0e-397ef822c802 Co-authored-by: schiller-manuel <[email protected]>
1 parent 012af22 commit 54d5258

6 files changed

Lines changed: 49 additions & 46 deletions

File tree

‎packages/router-generator/src/filesystem/physical/getRouteNodes.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'node:path'
22
import * as fsp from 'node:fs/promises'
33
import {
4+
cleanPath,
45
determineInitialRoutePath,
56
escapeRegExp,
67
hasEscapedLeadingUnderscore,
@@ -125,15 +126,17 @@ export async function getRouteNodes(
125126
const filePath = replaceBackslash(
126127
path.join(normalizedDir, node.filePath),
127128
)
128-
const routePath = `/${normalizedDir}${node.routePath}`
129+
const routePath = cleanPath(`/${normalizedDir}${node.routePath}`)
129130

130131
node.variableName = routePathToVariable(
131-
`${normalizedDir}/${removeExt(node.filePath)}`,
132+
cleanPath(`/${normalizedDir}/${removeExt(node.filePath)}`),
132133
)
133134
node.routePath = routePath
134135
// Keep originalRoutePath aligned with routePath for escape detection
135136
if (node.originalRoutePath) {
136-
node.originalRoutePath = `/${normalizedDir}${node.originalRoutePath}`
137+
node.originalRoutePath = cleanPath(
138+
`/${normalizedDir}${node.originalRoutePath}`,
139+
)
137140
}
138141
node.filePath = filePath
139142
// Virtual subtree nodes (from __virtual.ts) are embedded in a

‎packages/router-generator/tests/generator/virtual-inside-nested/routeTree.snapshot.ts‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import { Route as rootRouteImport } from './routes/__root'
1212
import { Route as IndexRouteImport } from './routes/index'
1313
import { Route as FooBarRouteImport } from './routes/foo/bar'
14-
import { Route as fooBarDetailsRouteImport } from './routes/foo/bar/details'
15-
import { Route as fooBarHomeRouteImport } from './routes/foo/bar/home'
14+
import { Route as FooBarDetailsRouteImport } from './routes/foo/bar/details'
15+
import { Route as FooBarHomeRouteImport } from './routes/foo/bar/home'
1616

1717
const IndexRoute = IndexRouteImport.update({
1818
id: '/',
@@ -24,12 +24,12 @@ const FooBarRoute = FooBarRouteImport.update({
2424
path: '/foo/bar',
2525
getParentRoute: () => rootRouteImport,
2626
} as any)
27-
const fooBarDetailsRoute = fooBarDetailsRouteImport.update({
27+
const FooBarDetailsRoute = FooBarDetailsRouteImport.update({
2828
id: '/$id',
2929
path: '/$id',
3030
getParentRoute: () => FooBarRoute,
3131
} as any)
32-
const fooBarHomeRoute = fooBarHomeRouteImport.update({
32+
const FooBarHomeRoute = FooBarHomeRouteImport.update({
3333
id: '/',
3434
path: '/',
3535
getParentRoute: () => FooBarRoute,
@@ -38,20 +38,20 @@ const fooBarHomeRoute = fooBarHomeRouteImport.update({
3838
export interface FileRoutesByFullPath {
3939
'/': typeof IndexRoute
4040
'/foo/bar': typeof FooBarRouteWithChildren
41-
'/foo/bar/': typeof fooBarHomeRoute
42-
'/foo/bar/$id': typeof fooBarDetailsRoute
41+
'/foo/bar/': typeof FooBarHomeRoute
42+
'/foo/bar/$id': typeof FooBarDetailsRoute
4343
}
4444
export interface FileRoutesByTo {
4545
'/': typeof IndexRoute
46-
'/foo/bar': typeof fooBarHomeRoute
47-
'/foo/bar/$id': typeof fooBarDetailsRoute
46+
'/foo/bar': typeof FooBarHomeRoute
47+
'/foo/bar/$id': typeof FooBarDetailsRoute
4848
}
4949
export interface FileRoutesById {
5050
__root__: typeof rootRouteImport
5151
'/': typeof IndexRoute
5252
'/foo/bar': typeof FooBarRouteWithChildren
53-
'/foo/bar/': typeof fooBarHomeRoute
54-
'/foo/bar/$id': typeof fooBarDetailsRoute
53+
'/foo/bar/': typeof FooBarHomeRoute
54+
'/foo/bar/$id': typeof FooBarDetailsRoute
5555
}
5656
export interface FileRouteTypes {
5757
fileRoutesByFullPath: FileRoutesByFullPath
@@ -86,27 +86,27 @@ declare module '@tanstack/react-router' {
8686
id: '/foo/bar/$id'
8787
path: '/$id'
8888
fullPath: '/foo/bar/$id'
89-
preLoaderRoute: typeof fooBarDetailsRouteImport
89+
preLoaderRoute: typeof FooBarDetailsRouteImport
9090
parentRoute: typeof FooBarRoute
9191
}
9292
'/foo/bar/': {
9393
id: '/foo/bar/'
9494
path: '/'
9595
fullPath: '/foo/bar/'
96-
preLoaderRoute: typeof fooBarHomeRouteImport
96+
preLoaderRoute: typeof FooBarHomeRouteImport
9797
parentRoute: typeof FooBarRoute
9898
}
9999
}
100100
}
101101

102102
interface FooBarRouteChildren {
103-
fooBarHomeRoute: typeof fooBarHomeRoute
104-
fooBarDetailsRoute: typeof fooBarDetailsRoute
103+
FooBarHomeRoute: typeof FooBarHomeRoute
104+
FooBarDetailsRoute: typeof FooBarDetailsRoute
105105
}
106106

107107
const FooBarRouteChildren: FooBarRouteChildren = {
108-
fooBarHomeRoute: fooBarHomeRoute,
109-
fooBarDetailsRoute: fooBarDetailsRoute,
108+
FooBarHomeRoute: FooBarHomeRoute,
109+
FooBarDetailsRoute: FooBarDetailsRoute,
110110
}
111111

112112
const FooBarRouteWithChildren =

‎packages/router-generator/tests/generator/virtual-inside-with-escaped-underscore/routeTree.snapshot.ts‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,49 @@
1010

1111
import { Route as rootRouteImport } from './routes/__root'
1212
import { Route as IndexRouteImport } from './routes/index'
13-
import { Route as nestedCallbackRouteImport } from './routes/nested/callback'
14-
import { Route as nestedAuthRouteImport } from './routes/nested/auth'
15-
import { Route as nestedHomeRouteImport } from './routes/nested/home'
13+
import { Route as NestedCallbackRouteImport } from './routes/nested/callback'
14+
import { Route as NestedAuthRouteImport } from './routes/nested/auth'
15+
import { Route as NestedHomeRouteImport } from './routes/nested/home'
1616

1717
const IndexRoute = IndexRouteImport.update({
1818
id: '/',
1919
path: '/',
2020
getParentRoute: () => rootRouteImport,
2121
} as any)
22-
const nestedCallbackRoute = nestedCallbackRouteImport.update({
22+
const NestedCallbackRoute = NestedCallbackRouteImport.update({
2323
id: '/nested/_callback',
2424
path: '/nested/_callback',
2525
getParentRoute: () => rootRouteImport,
2626
} as any)
27-
const nestedAuthRoute = nestedAuthRouteImport.update({
27+
const NestedAuthRoute = NestedAuthRouteImport.update({
2828
id: '/nested/_auth',
2929
path: '/nested/_auth',
3030
getParentRoute: () => rootRouteImport,
3131
} as any)
32-
const nestedHomeRoute = nestedHomeRouteImport.update({
32+
const NestedHomeRoute = NestedHomeRouteImport.update({
3333
id: '/nested/',
3434
path: '/nested/',
3535
getParentRoute: () => rootRouteImport,
3636
} as any)
3737

3838
export interface FileRoutesByFullPath {
3939
'/': typeof IndexRoute
40-
'/nested/': typeof nestedHomeRoute
41-
'/nested/_auth': typeof nestedAuthRoute
42-
'/nested/_callback': typeof nestedCallbackRoute
40+
'/nested/': typeof NestedHomeRoute
41+
'/nested/_auth': typeof NestedAuthRoute
42+
'/nested/_callback': typeof NestedCallbackRoute
4343
}
4444
export interface FileRoutesByTo {
4545
'/': typeof IndexRoute
46-
'/nested': typeof nestedHomeRoute
47-
'/nested/_auth': typeof nestedAuthRoute
48-
'/nested/_callback': typeof nestedCallbackRoute
46+
'/nested': typeof NestedHomeRoute
47+
'/nested/_auth': typeof NestedAuthRoute
48+
'/nested/_callback': typeof NestedCallbackRoute
4949
}
5050
export interface FileRoutesById {
5151
__root__: typeof rootRouteImport
5252
'/': typeof IndexRoute
53-
'/nested/': typeof nestedHomeRoute
54-
'/nested/_auth': typeof nestedAuthRoute
55-
'/nested/_callback': typeof nestedCallbackRoute
53+
'/nested/': typeof NestedHomeRoute
54+
'/nested/_auth': typeof NestedAuthRoute
55+
'/nested/_callback': typeof NestedCallbackRoute
5656
}
5757
export interface FileRouteTypes {
5858
fileRoutesByFullPath: FileRoutesByFullPath
@@ -64,9 +64,9 @@ export interface FileRouteTypes {
6464
}
6565
export interface RootRouteChildren {
6666
IndexRoute: typeof IndexRoute
67-
nestedHomeRoute: typeof nestedHomeRoute
68-
nestedAuthRoute: typeof nestedAuthRoute
69-
nestedCallbackRoute: typeof nestedCallbackRoute
67+
NestedHomeRoute: typeof NestedHomeRoute
68+
NestedAuthRoute: typeof NestedAuthRoute
69+
NestedCallbackRoute: typeof NestedCallbackRoute
7070
}
7171

7272
declare module '@tanstack/react-router' {
@@ -82,31 +82,31 @@ declare module '@tanstack/react-router' {
8282
id: '/nested/_callback'
8383
path: '/nested/_callback'
8484
fullPath: '/nested/_callback'
85-
preLoaderRoute: typeof nestedCallbackRouteImport
85+
preLoaderRoute: typeof NestedCallbackRouteImport
8686
parentRoute: typeof rootRouteImport
8787
}
8888
'/nested/_auth': {
8989
id: '/nested/_auth'
9090
path: '/nested/_auth'
9191
fullPath: '/nested/_auth'
92-
preLoaderRoute: typeof nestedAuthRouteImport
92+
preLoaderRoute: typeof NestedAuthRouteImport
9393
parentRoute: typeof rootRouteImport
9494
}
9595
'/nested/': {
9696
id: '/nested/'
9797
path: '/nested'
9898
fullPath: '/nested/'
99-
preLoaderRoute: typeof nestedHomeRouteImport
99+
preLoaderRoute: typeof NestedHomeRouteImport
100100
parentRoute: typeof rootRouteImport
101101
}
102102
}
103103
}
104104

105105
const rootRouteChildren: RootRouteChildren = {
106106
IndexRoute: IndexRoute,
107-
nestedHomeRoute: nestedHomeRoute,
108-
nestedAuthRoute: nestedAuthRoute,
109-
nestedCallbackRoute: nestedCallbackRoute,
107+
NestedHomeRoute: NestedHomeRoute,
108+
NestedAuthRoute: NestedAuthRoute,
109+
NestedCallbackRoute: NestedCallbackRoute,
110110
}
111111
export const routeTree = rootRouteImport
112112
._addFileChildren(rootRouteChildren)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createFileRoute } from '@tanstack/react-router'
22

3-
export const Route = createFileRoute('/s1/.//_layout/foo/')({
3+
export const Route = createFileRoute('/s1/_layout/foo/')({
44
component: () => <div>Nested home</div>,
55
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Outlet, createFileRoute } from '@tanstack/react-router'
22

3-
export const Route = createFileRoute('/s1/.//_layout/foo')({
3+
export const Route = createFileRoute('/s1/_layout/foo')({
44
component: () => <Outlet />,
55
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Outlet, createFileRoute } from '@tanstack/react-router'
22

3-
export const Route = createFileRoute('/s1/.//_layout')({
3+
export const Route = createFileRoute('/s1/_layout')({
44
component: () => <Outlet />,
55
})

0 commit comments

Comments
 (0)