Repository: TanStack/router
Pull request #1835 (2024-06-26 14:32:53)

fix(router-generator): add virtual parent for routes in addition to layouts
Currently the file-based route generator has a bug with `route.tsx` files, which causes the "parent" path to be lost. Creating a virtual parent for `route.tsx` files (similarly to `_layout` files) fixes this problem so that the path is retained. Example:
```
post/route.tsx
post/index.tsx
post/$id.tsx
```
Currently the presence of the `route.tsx` file causes `post/index.tsx` to be mapped to url path `/`, instead of being properly mapped to `/post/`. If you attempt to use `/post/`, it actually gets evaluated by `post/$id.tsx`, and `$id = post`.

The documentation [file-based-routing#file-naming-conventions](https://tanstack.com/router/latest/docs/framework/react/guide/file-based-routing#file-naming-conventions) seems to indicate that this is a bug:
> When using directories to organize your routes, the `route` suffix can be used to create a route file at the directory's path. For example, `blog.post.route.tsx` or `blog/post/route.tsx` can be used at the route file for the `/blog/post` route.

This description doesn't match current behavior; this code change should fix it.

schiller-manuel: can you please add a test for this?
nx-cloud[bot]: # ☁️ Nx Cloud Report

CI is running for commit 136b9fbbf3a07369f14286dcbeb508baa5b07cfe.

[📂 Click to track the progress, see the status, the terminal output, and the build insights.](https://cloud.nx.app/cipes/667c69f64a7c241c031ab930?utm_source=pull-request&utm_medium=comment)


---

Sent with 💌 from [NxCloud.](https://nx.app?utm_source=pull-request&utm_medium=comment)
schiller-manuel: looks like the existing tests fail with this change 

d-a-s: Sorry about that, it turns out it only seems to be a problem if you had a route inside of a layout directory (e.g. `_layout-a/route.tsx`). I've altered the code, added some tests for that scenario, and updated the relevant snapshot.

Patch:
diff --git a/examples/react/authenticated-routes/package.json b/examples/react/authenticated-routes/package.json
index ab9ee1c58..8353f5016 100644
--- a/examples/react/authenticated-routes/package.json
+++ b/examples/react/authenticated-routes/package.json
@@ -11,7 +11,7 @@
   "dependencies": {
     "@tanstack/react-router": "^1.40.0",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
+    "@tanstack/router-vite-plugin": "^1.40.2",
     "redaxios": "^0.5.0",
     "immer": "^10.0.3",
     "react": "^18.2.0",
diff --git a/examples/react/basic-file-based-codesplitting/package.json b/examples/react/basic-file-based-codesplitting/package.json
index 8d9f98af8..e79351656 100644
--- a/examples/react/basic-file-based-codesplitting/package.json
+++ b/examples/react/basic-file-based-codesplitting/package.json
@@ -11,7 +11,7 @@
   "dependencies": {
     "@tanstack/react-router": "^1.40.0",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
+    "@tanstack/router-vite-plugin": "^1.40.2",
     "redaxios": "^0.5.0",
     "immer": "^10.0.3",
     "react": "^18.2.0",
diff --git a/examples/react/basic-file-based/package.json b/examples/react/basic-file-based/package.json
index 671aac4f1..5e2c06e4b 100644
--- a/examples/react/basic-file-based/package.json
+++ b/examples/react/basic-file-based/package.json
@@ -11,7 +11,7 @@
   "dependencies": {
     "@tanstack/react-router": "^1.40.0",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
+    "@tanstack/router-vite-plugin": "^1.40.2",
     "redaxios": "^0.5.0",
     "immer": "^10.0.3",
     "react": "^18.2.0",
diff --git a/examples/react/basic-react-query-file-based/package.json b/examples/react/basic-react-query-file-based/package.json
index 48e156bf9..7d3cf7603 100644
--- a/examples/react/basic-react-query-file-based/package.json
+++ b/examples/react/basic-react-query-file-based/package.json
@@ -13,7 +13,7 @@
     "@tanstack/react-query-devtools": "^5.17.8",
     "@tanstack/react-router": "^1.40.0",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
+    "@tanstack/router-vite-plugin": "^1.40.2",
     "redaxios": "^0.5.0",
     "immer": "^10.0.3",
     "react": "^18.2.0",
diff --git a/examples/react/basic-ssr-file-based/package.json b/examples/react/basic-ssr-file-based/package.json
index b26652e86..22ebc6d87 100644
--- a/examples/react/basic-ssr-file-based/package.json
+++ b/examples/react/basic-ssr-file-based/package.json
@@ -13,9 +13,9 @@
   },
   "dependencies": {
     "@tanstack/react-router": "^1.40.0",
-    "@tanstack/start": "^1.40.1",
+    "@tanstack/start": "^1.40.2",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
+    "@tanstack/router-vite-plugin": "^1.40.2",
     "redaxios": "^0.5.0",
     "get-port": "^7.0.0",
     "react": "^18.2.0",
diff --git a/examples/react/basic-ssr-streaming-file-based/package.json b/examples/react/basic-ssr-streaming-file-based/package.json
index 4823d8880..0e38ffbaa 100644
--- a/examples/react/basic-ssr-streaming-file-based/package.json
+++ b/examples/react/basic-ssr-streaming-file-based/package.json
@@ -13,9 +13,9 @@
   },
   "dependencies": {
     "@tanstack/react-router": "^1.40.0",
-    "@tanstack/start": "^1.40.1",
+    "@tanstack/start": "^1.40.2",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
+    "@tanstack/router-vite-plugin": "^1.40.2",
     "redaxios": "^0.5.0",
     "get-port": "^7.0.0",
     "react": "^18.2.0",
diff --git a/examples/react/kitchen-sink-file-based/package.json b/examples/react/kitchen-sink-file-based/package.json
index 921fdf722..f65945fb2 100644
--- a/examples/react/kitchen-sink-file-based/package.json
+++ b/examples/react/kitchen-sink-file-based/package.json
@@ -11,7 +11,7 @@
   "dependencies": {
     "@tanstack/react-router": "^1.40.0",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
+    "@tanstack/router-vite-plugin": "^1.40.2",
     "redaxios": "^0.5.0",
     "immer": "^10.0.3",
     "react": "^18.2.0",
diff --git a/examples/react/kitchen-sink-react-query-file-based/package.json b/examples/react/kitchen-sink-react-query-file-based/package.json
index 407a84e15..1dab0f9cb 100644
--- a/examples/react/kitchen-sink-react-query-file-based/package.json
+++ b/examples/react/kitchen-sink-react-query-file-based/package.json
@@ -13,7 +13,7 @@
     "@tanstack/react-query-devtools": "^5.17.8",
     "@tanstack/react-router": "^1.40.0",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
+    "@tanstack/router-vite-plugin": "^1.40.2",
     "redaxios": "^0.5.0",
     "immer": "^10.0.3",
     "react": "^18.2.0",
diff --git a/examples/react/large-file-based/package.json b/examples/react/large-file-based/package.json
index 613635b1e..565ea7a31 100644
--- a/examples/react/large-file-based/package.json
+++ b/examples/react/large-file-based/package.json
@@ -14,7 +14,7 @@
     "@tanstack/react-query": "^5.17.8",
     "@tanstack/react-router": "^1.40.0",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
+    "@tanstack/router-vite-plugin": "^1.40.2",
     "redaxios": "^0.5.0",
     "immer": "^10.0.3",
     "react": "^18.2.0",
diff --git a/examples/react/quickstart-file-based/package.json b/examples/react/quickstart-file-based/package.json
index d4e6b5955..4b3592f5e 100644
--- a/examples/react/quickstart-file-based/package.json
+++ b/examples/react/quickstart-file-based/package.json
@@ -11,7 +11,7 @@
   "dependencies": {
     "@tanstack/react-router": "^1.40.0",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
+    "@tanstack/router-vite-plugin": "^1.40.2",
     "redaxios": "^0.5.0",
     "immer": "^10.0.3",
     "react": "^18.2.0",
diff --git a/examples/react/quickstart-rspack-file-based/package.json b/examples/react/quickstart-rspack-file-based/package.json
index e247181b5..06f4522b7 100644
--- a/examples/react/quickstart-rspack-file-based/package.json
+++ b/examples/react/quickstart-rspack-file-based/package.json
@@ -16,7 +16,7 @@
   "devDependencies": {
     "@rsbuild/core": "^0.7.9",
     "@rsbuild/plugin-react": "^0.7.9",
-    "@tanstack/router-plugin": "^1.39.13",
+    "@tanstack/router-plugin": "^1.40.2",
     "@types/react": "^18.3.3",
     "@types/react-dom": "^18.3.0",
     "typescript": "^5.4.2"
diff --git a/examples/react/start-basic-rsc/package.json b/examples/react/start-basic-rsc/package.json
index a80972d12..dabf50890 100644
--- a/examples/react/start-basic-rsc/package.json
+++ b/examples/react/start-basic-rsc/package.json
@@ -14,8 +14,8 @@
   "dependencies": {
     "@tanstack/react-router": "^1.40.0",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
-    "@tanstack/start": "^1.40.1",
+    "@tanstack/router-vite-plugin": "^1.40.2",
+    "@tanstack/start": "^1.40.2",
     "redaxios": "^0.5.0",
     "isbot": "^3.7.0",
     "react": "^18.3.1",
diff --git a/examples/react/start-basic/package.json b/examples/react/start-basic/package.json
index 282a8f2be..259a73dd6 100644
--- a/examples/react/start-basic/package.json
+++ b/examples/react/start-basic/package.json
@@ -16,8 +16,8 @@
   "dependencies": {
     "@tanstack/react-router": "^1.40.0",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
-    "@tanstack/start": "^1.40.1",
+    "@tanstack/router-vite-plugin": "^1.40.2",
+    "@tanstack/start": "^1.40.2",
     "@typescript-eslint/parser": "^7.2.0",
     "@vitejs/plugin-react": "^4",
     "dotenv": "^16.4.5",
diff --git a/examples/react/start-trellaux/package.json b/examples/react/start-trellaux/package.json
index 8406f03de..eaa66ae24 100644
--- a/examples/react/start-trellaux/package.json
+++ b/examples/react/start-trellaux/package.json
@@ -16,8 +16,8 @@
     "@tanstack/react-query-devtools": "^5.40.0",
     "@tanstack/react-router": "^1.40.0",
     "@tanstack/router-devtools": "^1.40.0",
-    "@tanstack/router-vite-plugin": "^1.39.13",
-    "@tanstack/start": "^1.40.1",
+    "@tanstack/router-vite-plugin": "^1.40.2",
+    "@tanstack/start": "^1.40.2",
     "@typescript-eslint/parser": "^7.2.0",
     "@vitejs/plugin-react": "^4",
     "isbot": "^3.7.0",
diff --git a/examples/react/wip-with-bling/package.json b/examples/react/wip-with-bling/package.json
index f54bd2e5d..454a27d5a 100644
--- a/examples/react/wip-with-bling/package.json
+++ b/examples/react/wip-with-bling/package.json
@@ -14,7 +14,7 @@
   "dependencies": {
     "@tanstack/bling": "^0.5.0",
     "@tanstack/react-router": "^1.40.0",
-    "@tanstack/start": "^1.40.1",
+    "@tanstack/start": "^1.40.2",
     "@tanstack/react-store": "^0.2.1",
     "@tanstack/router-devtools": "^1.40.0",
     "redaxios": "^0.5.0",
diff --git a/packages/router-generator/src/generator.ts b/packages/router-generator/src/generator.ts
index f07289c59..b5b0a40d4 100644
--- a/packages/router-generator/src/generator.ts
+++ b/packages/router-generator/src/generator.ts
@@ -350,7 +350,9 @@ export async function generator(config: Config) {
     }
 
     const cleanedPathIsEmpty = (node.cleanedPath || '').length === 0
-    node.isVirtualParentRequired = node.isLayout ? !cleanedPathIsEmpty : false
+    const nonPathRoute = node.isRoute && node.isNonPath
+    node.isVirtualParentRequired =
+      node.isLayout || nonPathRoute ? !cleanedPathIsEmpty : false
     if (!node.isVirtual && node.isVirtualParentRequired) {
       const parentRoutePath = removeLastSegmentFromPath(node.routePath) || '/'
       const parentVariableName = routePathToVariable(parentRoutePath)
diff --git a/packages/router-plugin/package.json b/packages/router-plugin/package.json
index 3afaca240..db7be530d 100644
--- a/packages/router-plugin/package.json
+++ b/packages/router-plugin/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/router-plugin",
-  "version": "1.39.13",
+  "version": "1.40.2",
   "description": "",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/router-vite-plugin/package.json b/packages/router-vite-plugin/package.json
index f086b84cc..ee1c2df14 100644
--- a/packages/router-vite-plugin/package.json
+++ b/packages/router-vite-plugin/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/router-vite-plugin",
-  "version": "1.39.13",
+  "version": "1.40.2",
   "description": "",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/start-vite-plugin/package.json b/packages/start-vite-plugin/package.json
index 831ecfbff..2a0980f32 100644
--- a/packages/start-vite-plugin/package.json
+++ b/packages/start-vite-plugin/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/start-vite-plugin",
-  "version": "1.39.1",
+  "version": "1.40.2",
   "description": "",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/start/package.json b/packages/start/package.json
index adc9380af..7bf76c04a 100644
--- a/packages/start/package.json
+++ b/packages/start/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/start",
-  "version": "1.40.1",
+  "version": "1.40.2",
   "description": "",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/start/src/config/index.ts b/packages/start/src/config/index.ts
index 6fe8d38d3..53eb7bba1 100644
--- a/packages/start/src/config/index.ts
+++ b/packages/start/src/config/index.ts
@@ -38,6 +38,8 @@ const babelSchema = z
 const reactSchema = z
   .object({
     babel: babelSchema,
+    exclude: z.array(z.instanceof(RegExp)).optional(),
+    include: z.array(z.instanceof(RegExp)).optional(),
   })
   .optional()
   .default({})
@@ -171,6 +173,8 @@ export async function defineConfig(opts_?: z.infer<typeof optsSchema>) {
           }),
           reactRefresh({
             babel: opts.react.babel,
+            exclude: opts.react.exclude,
+            include: opts.react.include,
           }),
           // serverComponents.client(),
         ],


Test patch:
diff --git a/packages/router-generator/tests/generator/nested-layouts/routeTree.snapshot.ts b/packages/router-generator/tests/generator/nested-layouts/routeTree.snapshot.ts
index 95498c219..5b4badb97 100644
--- a/packages/router-generator/tests/generator/nested-layouts/routeTree.snapshot.ts
+++ b/packages/router-generator/tests/generator/nested-layouts/routeTree.snapshot.ts
@@ -21,21 +21,26 @@ import { Route as NestedLayoutB2Import } from './routes/nested/_layout-b2'
 import { Route as NestedLayoutB1Import } from './routes/nested/_layout-b1'
 import { Route as JestedLayoutB4Import } from './routes/jested/_layout-b4'
 import { Route as JestedLayoutB3Import } from './routes/jested/_layout-b3'
+import { Route as FooBarImport } from './routes/foo/bar'
 import { Route as LayoutA2BarImport } from './routes/_layout-a2/bar'
 import { Route as LayoutA1FooImport } from './routes/_layout-a1/foo'
 import { Route as folderInFolderImport } from './routes/(folder)/in-folder'
+import { Route as FooLayoutB5RouteImport } from './routes/foo/_layout-b5/route'
 import { Route as NestedLayoutB1IndexImport } from './routes/nested/_layout-b1/index'
 import { Route as JestedLayoutB3IndexImport } from './routes/jested/_layout-b3/index'
+import { Route as FooLayoutB5IndexImport } from './routes/foo/_layout-b5/index'
 import { Route as NestedLayoutB2FooImport } from './routes/nested/_layout-b2/foo'
 import { Route as NestedLayoutB1LayoutC1Import } from './routes/nested/_layout-b1/_layout-c1'
 import { Route as JestedLayoutB4FooImport } from './routes/jested/_layout-b4/foo'
 import { Route as JestedLayoutB3LayoutC2Import } from './routes/jested/_layout-b3/_layout-c2'
+import { Route as FooLayoutB5IdImport } from './routes/foo/_layout-b5/$id'
 import { Route as NestedLayoutB1LayoutC1BarImport } from './routes/nested/_layout-b1/_layout-c1/bar'
 import { Route as JestedLayoutB3LayoutC2BarImport } from './routes/jested/_layout-b3/_layout-c2/bar'
 
 // Create Virtual Routes
 
 const NestedImport = createFileRoute('/nested')()
+const FooImport = createFileRoute('/foo')()
 
 // Create/Update Routes
 
@@ -44,6 +49,11 @@ const NestedRoute = NestedImport.update({
   getParentRoute: () => rootRoute,
 } as any)
 
+const FooRoute = FooImport.update({
+  path: '/foo',
+  getParentRoute: () => rootRoute,
+} as any)
+
 const LayoutA2Route = LayoutA2Import.update({
   id: '/_layout-a2',
   getParentRoute: () => rootRoute,
@@ -84,6 +94,11 @@ const JestedLayoutB3Route = JestedLayoutB3Import.update({
   getParentRoute: () => JestedRouteRoute,
 } as any)
 
+const FooBarRoute = FooBarImport.update({
+  path: '/bar',
+  getParentRoute: () => FooRoute,
+} as any)
+
 const LayoutA2BarRoute = LayoutA2BarImport.update({
   path: '/bar',
   getParentRoute: () => LayoutA2Route,
@@ -99,6 +114,11 @@ const folderInFolderRoute = folderInFolderImport.update({
   getParentRoute: () => rootRoute,
 } as any)
 
+const FooLayoutB5RouteRoute = FooLayoutB5RouteImport.update({
+  id: '/foo/_layout-b5',
+  getParentRoute: () => FooRoute,
+} as any)
+
 const NestedLayoutB1IndexRoute = NestedLayoutB1IndexImport.update({
   path: '/',
   getParentRoute: () => NestedLayoutB1Route,
@@ -109,6 +129,11 @@ const JestedLayoutB3IndexRoute = JestedLayoutB3IndexImport.update({
   getParentRoute: () => JestedLayoutB3Route,
 } as any)
 
+const FooLayoutB5IndexRoute = FooLayoutB5IndexImport.update({
+  path: '/',
+  getParentRoute: () => FooLayoutB5RouteRoute,
+} as any)
+
 const NestedLayoutB2FooRoute = NestedLayoutB2FooImport.update({
   path: '/foo',
   getParentRoute: () => NestedLayoutB2Route,
@@ -129,6 +154,11 @@ const JestedLayoutB3LayoutC2Route = JestedLayoutB3LayoutC2Import.update({
   getParentRoute: () => JestedLayoutB3Route,
 } as any)
 
+const FooLayoutB5IdRoute = FooLayoutB5IdImport.update({
+  path: '/$id',
+  getParentRoute: () => FooLayoutB5RouteRoute,
+} as any)
+
 const NestedLayoutB1LayoutC1BarRoute = NestedLayoutB1LayoutC1BarImport.update({
   path: '/bar',
   getParentRoute: () => NestedLayoutB1LayoutC1Route,
@@ -171,6 +201,20 @@ declare module '@tanstack/react-router' {
       preLoaderRoute: typeof LayoutA2Import
       parentRoute: typeof rootRoute
     }
+    '/foo': {
+      id: '/foo'
+      path: '/foo'
+      fullPath: '/foo'
+      preLoaderRoute: typeof FooImport
+      parentRoute: typeof rootRoute
+    }
+    '/foo/_layout-b5': {
+      id: '/foo/_layout-b5'
+      path: '/foo'
+      fullPath: '/foo'
+      preLoaderRoute: typeof FooLayoutB5RouteImport
+      parentRoute: typeof FooRoute
+    }
     '/(folder)/in-folder': {
       id: '/in-folder'
       path: '/in-folder'
@@ -192,6 +236,13 @@ declare module '@tanstack/react-router' {
       preLoaderRoute: typeof LayoutA2BarImport
       parentRoute: typeof LayoutA2Import
     }
+    '/foo/bar': {
+      id: '/foo/bar'
+      path: '/bar'
+      fullPath: '/foo/bar'
+      preLoaderRoute: typeof FooBarImport
+      parentRoute: typeof FooImport
+    }
     '/jested/_layout-b3': {
       id: '/jested/_layout-b3'
       path: ''
@@ -227,6 +278,13 @@ declare module '@tanstack/react-router' {
       preLoaderRoute: typeof NestedLayoutB2Import
       parentRoute: typeof NestedImport
     }
+    '/foo/_layout-b5/$id': {
+      id: '/foo/_layout-b5/$id'
+      path: '/$id'
+      fullPath: '/foo/$id'
+      preLoaderRoute: typeof FooLayoutB5IdImport
+      parentRoute: typeof FooLayoutB5RouteImport
+    }
     '/jested/_layout-b3/_layout-c2': {
       id: '/jested/_layout-b3/_layout-c2'
       path: ''
@@ -255,6 +313,13 @@ declare module '@tanstack/react-router' {
       preLoaderRoute: typeof NestedLayoutB2FooImport
       parentRoute: typeof NestedLayoutB2Import
     }
+    '/foo/_layout-b5/': {
+      id: '/foo/_layout-b5/'
+      path: '/'
+      fullPath: '/foo/'
+      preLoaderRoute: typeof FooLayoutB5IndexImport
+      parentRoute: typeof FooLayoutB5RouteImport
+    }
     '/jested/_layout-b3/': {
       id: '/jested/_layout-b3/'
       path: '/'
@@ -303,6 +368,13 @@ export const routeTree = rootRoute.addChildren({
   }),
   LayoutA1Route: LayoutA1Route.addChildren({ LayoutA1FooRoute }),
   LayoutA2Route: LayoutA2Route.addChildren({ LayoutA2BarRoute }),
+  FooRoute: FooRoute.addChildren({
+    FooLayoutB5RouteRoute: FooLayoutB5RouteRoute.addChildren({
+      FooLayoutB5IdRoute,
+      FooLayoutB5IndexRoute,
+    }),
+    FooBarRoute,
+  }),
   folderInFolderRoute,
   NestedRoute: NestedRoute.addChildren({
     NestedLayoutB1Route: NestedLayoutB1Route.addChildren({
@@ -329,6 +401,7 @@ export const routeTree = rootRoute.addChildren({
         "/jested",
         "/_layout-a1",
         "/_layout-a2",
+        "/foo",
         "/in-folder",
         "/nested"
       ]
@@ -355,6 +428,21 @@ export const routeTree = rootRoute.addChildren({
         "/_layout-a2/bar"
       ]
     },
+    "/foo": {
+      "filePath": "foo/_layout-b5",
+      "children": [
+        "/foo/_layout-b5",
+        "/foo/bar"
+      ]
+    },
+    "/foo/_layout-b5": {
+      "filePath": "foo/_layout-b5/route.tsx",
+      "parent": "/foo",
+      "children": [
+        "/foo/_layout-b5/$id",
+        "/foo/_layout-b5/"
+      ]
+    },
     "/in-folder": {
       "filePath": "(folder)/in-folder.tsx"
     },
@@ -366,6 +454,10 @@ export const routeTree = rootRoute.addChildren({
       "filePath": "_layout-a2/bar.tsx",
       "parent": "/_layout-a2"
     },
+    "/foo/bar": {
+      "filePath": "foo/bar.tsx",
+      "parent": "/foo"
+    },
     "/jested/_layout-b3": {
       "filePath": "jested/_layout-b3.tsx",
       "parent": "/jested",
@@ -403,6 +495,10 @@ export const routeTree = rootRoute.addChildren({
         "/nested/_layout-b2/foo"
       ]
     },
+    "/foo/_layout-b5/$id": {
+      "filePath": "foo/_layout-b5/$id.tsx",
+      "parent": "/foo/_layout-b5"
+    },
     "/jested/_layout-b3/_layout-c2": {
       "filePath": "jested/_layout-b3/_layout-c2.tsx",
       "parent": "/jested/_layout-b3",
@@ -425,6 +521,10 @@ export const routeTree = rootRoute.addChildren({
       "filePath": "nested/_layout-b2/foo.tsx",
       "parent": "/nested/_layout-b2"
     },
+    "/foo/_layout-b5/": {
+      "filePath": "foo/_layout-b5/index.tsx",
+      "parent": "/foo/_layout-b5"
+    },
     "/jested/_layout-b3/": {
       "filePath": "jested/_layout-b3/index.tsx",
       "parent": "/jested/_layout-b3"
diff --git a/packages/router-generator/tests/generator/nested-layouts/routes/foo/_layout-b5/$id.tsx b/packages/router-generator/tests/generator/nested-layouts/routes/foo/_layout-b5/$id.tsx
new file mode 100644
index 000000000..ab504e42e
--- /dev/null
+++ b/packages/router-generator/tests/generator/nested-layouts/routes/foo/_layout-b5/$id.tsx
@@ -0,0 +1,1 @@
+/** */
diff --git a/packages/router-generator/tests/generator/nested-layouts/routes/foo/_layout-b5/index.tsx b/packages/router-generator/tests/generator/nested-layouts/routes/foo/_layout-b5/index.tsx
new file mode 100644
index 000000000..ab504e42e
--- /dev/null
+++ b/packages/router-generator/tests/generator/nested-layouts/routes/foo/_layout-b5/index.tsx
@@ -0,0 +1,1 @@
+/** */
diff --git a/packages/router-generator/tests/generator/nested-layouts/routes/foo/_layout-b5/route.tsx b/packages/router-generator/tests/generator/nested-layouts/routes/foo/_layout-b5/route.tsx
new file mode 100644
index 000000000..ab504e42e
--- /dev/null
+++ b/packages/router-generator/tests/generator/nested-layouts/routes/foo/_layout-b5/route.tsx
@@ -0,0 +1,1 @@
+/** */
diff --git a/packages/router-generator/tests/generator/nested-layouts/routes/foo/bar.tsx b/packages/router-generator/tests/generator/nested-layouts/routes/foo/bar.tsx
new file mode 100644
index 000000000..ab504e42e
--- /dev/null
+++ b/packages/router-generator/tests/generator/nested-layouts/routes/foo/bar.tsx
@@ -0,0 +1,1 @@
+/** */