diff --git a/.changeset/deterministic-route-tree-sort.md b/.changeset/deterministic-route-tree-sort.md new file mode 100644 index 0000000000..2ec33196cd --- /dev/null +++ b/.changeset/deterministic-route-tree-sort.md @@ -0,0 +1,5 @@ +--- +"@tanstack/router-generator": patch +--- + +Make `buildRouteTree` route ordering deterministic. Its final sort tiebreaker compared whole route-node objects (`(d) => d`), which coerce to `"[object Object]"` and so never order — an inconsistent comparator that left routes tying on segment-count/index-token in an engine- and input-dependent order, producing non-deterministic `routeTree.gen.ts` diffs across machines. The tiebreaker now compares `routePath`, mirroring the pre-sort and giving a stable total order. diff --git a/packages/router-generator/src/generator.ts b/packages/router-generator/src/generator.ts index 4203f2b44f..e8cd170e40 100644 --- a/packages/router-generator/src/generator.ts +++ b/packages/router-generator/src/generator.ts @@ -38,6 +38,7 @@ import { removeLayoutSegmentsAndUnderscoresWithEscape, removeTrailingSlash, replaceBackslash, + sortRouteNodes, trimPathLeft, } from './utils' import { fillTemplate, getTargetTemplate } from './template' @@ -616,19 +617,10 @@ export class Generator { ? this.indexTokenSegmentRegex : createTokenRegex(config.indexToken, { type: 'segment' }) - const sortedRouteNodes = multiSortBy(acc.routeNodes, [ - (d) => (d.routePath?.includes(`/${rootPathId}`) ? -1 : 1), - (d) => - d.routePath === undefined - ? undefined - : countSlashSeparatedParts(d.routePath), - (d) => { - const segments = d.routePath?.split('/').filter(Boolean) ?? [] - const last = segments[segments.length - 1] ?? '' - return indexTokenSegmentRegex.test(last) ? -1 : 1 - }, - (d) => d, - ]) + const sortedRouteNodes = sortRouteNodes( + acc.routeNodes, + indexTokenSegmentRegex, + ) const routeImports: Array = [] const virtualRouteNodes: Array = [] diff --git a/packages/router-generator/src/index.ts b/packages/router-generator/src/index.ts index 9a4f8a17ff..4f3c7c7a14 100644 --- a/packages/router-generator/src/index.ts +++ b/packages/router-generator/src/index.ts @@ -23,6 +23,7 @@ export { removeUnderscores, resetRegex, multiSortBy, + sortRouteNodes, writeIfDifferent, format, removeExt, diff --git a/packages/router-generator/src/utils.ts b/packages/router-generator/src/utils.ts index 2354c5ed1c..ae6ee46ab6 100644 --- a/packages/router-generator/src/utils.ts +++ b/packages/router-generator/src/utils.ts @@ -123,6 +123,38 @@ export function multiSortBy( return result } +/** + * Sorts route nodes into the deterministic order used when generating the route + * tree. Precedence: root (`__root`) first, then by slash-separated segment + * count, then index segments before non-index, and finally — the tiebreaker — + * by `routePath`. + * + * The `routePath` tiebreaker is load-bearing: `routePath` is unique per node, so + * it gives the comparator a total order. Without it (e.g. comparing whole route + * nodes), any nodes tying on every earlier key are left in an engine- and + * input-order-dependent order by `Array.prototype.sort`, which makes the + * generated route tree churn non-deterministically across machines and Node + * versions. + */ +export function sortRouteNodes( + routeNodes: Array, + indexTokenSegmentRegex: RegExp, +): Array { + return multiSortBy(routeNodes, [ + (d) => (d.routePath?.includes(`/${rootPathId}`) ? -1 : 1), + (d) => + d.routePath === undefined + ? undefined + : countSlashSeparatedParts(d.routePath), + (d) => { + const segments = d.routePath?.split('/').filter(Boolean) ?? [] + const last = segments[segments.length - 1] ?? '' + return indexTokenSegmentRegex.test(last) ? -1 : 1 + }, + (d) => d.routePath, + ]) +} + export function cleanPath(path: string) { // remove double slashes return path.replace(/\/{2,}/g, '/') diff --git a/packages/router-generator/tests/generator/add-extensions-custom/routeTree.snapshot.ts b/packages/router-generator/tests/generator/add-extensions-custom/routeTree.snapshot.ts index 7859b1f9ff..2e6aa9d355 100644 --- a/packages/router-generator/tests/generator/add-extensions-custom/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/add-extensions-custom/routeTree.snapshot.ts @@ -9,19 +9,19 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root.js' -import { Route as PostsRouteImport } from './routes/posts.js' import { Route as IndexRouteImport } from './routes/index.js' +import { Route as PostsRouteImport } from './routes/posts.js' -const PostsRoute = PostsRouteImport.update({ - id: '/posts', - path: '/posts', - getParentRoute: () => rootRouteImport, -} as any) const IndexRoute = IndexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) +const PostsRoute = PostsRouteImport.update({ + id: '/posts', + path: '/posts', + getParentRoute: () => rootRouteImport, +} as any) export interface FileRoutesByFullPath { '/': typeof IndexRoute @@ -51,13 +51,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/posts': { - id: '/posts' - path: '/posts' - fullPath: '/posts' - preLoaderRoute: typeof PostsRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -65,6 +58,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } + '/posts': { + id: '/posts' + path: '/posts' + fullPath: '/posts' + preLoaderRoute: typeof PostsRouteImport + parentRoute: typeof rootRouteImport + } } } diff --git a/packages/router-generator/tests/generator/custom-scaffolding/routeTree.snapshot.ts b/packages/router-generator/tests/generator/custom-scaffolding/routeTree.snapshot.ts index e80d1e7e73..8f0ed564f4 100644 --- a/packages/router-generator/tests/generator/custom-scaffolding/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/custom-scaffolding/routeTree.snapshot.ts @@ -16,16 +16,16 @@ import { Route as ApiBarRouteImport } from './routes/api/bar' const FooLazyRouteImport = createFileRoute('/foo')() -const FooLazyRoute = FooLazyRouteImport.update({ - id: '/foo', - path: '/foo', - getParentRoute: () => rootRouteImport, -} as any).lazy(() => import('./routes/foo.lazy').then((d) => d.Route)) const IndexRoute = IndexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) +const FooLazyRoute = FooLazyRouteImport.update({ + id: '/foo', + path: '/foo', + getParentRoute: () => rootRouteImport, +} as any).lazy(() => import('./routes/foo.lazy').then((d) => d.Route)) const ApiBarRoute = ApiBarRouteImport.update({ id: '/api/bar', path: '/api/bar', @@ -64,13 +64,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/foo': { - id: '/foo' - path: '/foo' - fullPath: '/foo' - preLoaderRoute: typeof FooLazyRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -78,6 +71,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } + '/foo': { + id: '/foo' + path: '/foo' + fullPath: '/foo' + preLoaderRoute: typeof FooLazyRouteImport + parentRoute: typeof rootRouteImport + } '/api/bar': { id: '/api/bar' path: '/api/bar' diff --git a/packages/router-generator/tests/generator/custom-tokens/routeTree.snapshot.ts b/packages/router-generator/tests/generator/custom-tokens/routeTree.snapshot.ts index f49d059f20..fc136dc277 100644 --- a/packages/router-generator/tests/generator/custom-tokens/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/custom-tokens/routeTree.snapshot.ts @@ -9,18 +9,18 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as PostsR0ut3RouteImport } from './routes/posts/_r0ut3_' -import { Route as BlogR0ut3RouteImport } from './routes/blog/_r0ut3_' import { Route as R1nd3xRouteImport } from './routes/_1nd3x' -import { Route as Posts1nd3xRouteImport } from './routes/posts/_1nd3x' +import { Route as BlogR0ut3RouteImport } from './routes/blog/_r0ut3_' +import { Route as PostsR0ut3RouteImport } from './routes/posts/_r0ut3_' import { Route as Blog1nd3xRouteImport } from './routes/blog/_1nd3x' import { Route as BlogSlugRouteImport } from './routes/blog/$slug' +import { Route as Posts1nd3xRouteImport } from './routes/posts/_1nd3x' import { Route as PostsPostId1nd3xRouteImport } from './routes/posts/$postId/_1nd3x' import { Route as PostsPostIdDeepRouteImport } from './routes/posts/$postId/deep' -const PostsR0ut3Route = PostsR0ut3RouteImport.update({ - id: '/posts', - path: '/posts', +const R1nd3xRoute = R1nd3xRouteImport.update({ + id: '/', + path: '/', getParentRoute: () => rootRouteImport, } as any) const BlogR0ut3Route = BlogR0ut3RouteImport.update({ @@ -28,16 +28,11 @@ const BlogR0ut3Route = BlogR0ut3RouteImport.update({ path: '/blog', getParentRoute: () => rootRouteImport, } as any) -const R1nd3xRoute = R1nd3xRouteImport.update({ - id: '/', - path: '/', +const PostsR0ut3Route = PostsR0ut3RouteImport.update({ + id: '/posts', + path: '/posts', getParentRoute: () => rootRouteImport, } as any) -const Posts1nd3xRoute = Posts1nd3xRouteImport.update({ - id: '/', - path: '/', - getParentRoute: () => PostsR0ut3Route, -} as any) const Blog1nd3xRoute = Blog1nd3xRouteImport.update({ id: '/', path: '/', @@ -48,6 +43,11 @@ const BlogSlugRoute = BlogSlugRouteImport.update({ path: '/$slug', getParentRoute: () => BlogR0ut3Route, } as any) +const Posts1nd3xRoute = Posts1nd3xRouteImport.update({ + id: '/', + path: '/', + getParentRoute: () => PostsR0ut3Route, +} as any) const PostsPostId1nd3xRoute = PostsPostId1nd3xRouteImport.update({ id: '/$postId/', path: '/$postId/', @@ -127,11 +127,11 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/posts': { - id: '/posts' - path: '/posts' - fullPath: '/posts' - preLoaderRoute: typeof PostsR0ut3RouteImport + '/': { + id: '/' + path: '/' + fullPath: '/' + preLoaderRoute: typeof R1nd3xRouteImport parentRoute: typeof rootRouteImport } '/blog': { @@ -141,20 +141,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof BlogR0ut3RouteImport parentRoute: typeof rootRouteImport } - '/': { - id: '/' - path: '/' - fullPath: '/' - preLoaderRoute: typeof R1nd3xRouteImport + '/posts': { + id: '/posts' + path: '/posts' + fullPath: '/posts' + preLoaderRoute: typeof PostsR0ut3RouteImport parentRoute: typeof rootRouteImport } - '/posts/': { - id: '/posts/' - path: '/' - fullPath: '/posts/' - preLoaderRoute: typeof Posts1nd3xRouteImport - parentRoute: typeof PostsR0ut3Route - } '/blog/': { id: '/blog/' path: '/' @@ -169,6 +162,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof BlogSlugRouteImport parentRoute: typeof BlogR0ut3Route } + '/posts/': { + id: '/posts/' + path: '/' + fullPath: '/posts/' + preLoaderRoute: typeof Posts1nd3xRouteImport + parentRoute: typeof PostsR0ut3Route + } '/posts/$postId/': { id: '/posts/$postId/' path: '/$postId' diff --git a/packages/router-generator/tests/generator/dot-escaped/routeTree.snapshot.ts b/packages/router-generator/tests/generator/dot-escaped/routeTree.snapshot.ts index 2ccc3a0a38..815dba6590 100644 --- a/packages/router-generator/tests/generator/dot-escaped/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/dot-escaped/routeTree.snapshot.ts @@ -9,25 +9,20 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as ScriptDotjsRouteImport } from './routes/script[.]js' import { Route as NestedDotjsRouteImport } from './routes/nested[.]js' -import { Route as NestedDotjsScriptDotjsRouteImport } from './routes/nested[.]js.script[.]js' +import { Route as ScriptDotjsRouteImport } from './routes/script[.]js' import { Route as NestedDotjsDoubleDotextDotjsRouteImport } from './routes/nested[.]js.double[.]ext[.]js' +import { Route as NestedDotjsScriptDotjsRouteImport } from './routes/nested[.]js.script[.]js' -const ScriptDotjsRoute = ScriptDotjsRouteImport.update({ - id: '/script.js', - path: '/script.js', - getParentRoute: () => rootRouteImport, -} as any) const NestedDotjsRoute = NestedDotjsRouteImport.update({ id: '/nested.js', path: '/nested.js', getParentRoute: () => rootRouteImport, } as any) -const NestedDotjsScriptDotjsRoute = NestedDotjsScriptDotjsRouteImport.update({ +const ScriptDotjsRoute = ScriptDotjsRouteImport.update({ id: '/script.js', path: '/script.js', - getParentRoute: () => NestedDotjsRoute, + getParentRoute: () => rootRouteImport, } as any) const NestedDotjsDoubleDotextDotjsRoute = NestedDotjsDoubleDotextDotjsRouteImport.update({ @@ -35,6 +30,11 @@ const NestedDotjsDoubleDotextDotjsRoute = path: '/double.ext.js', getParentRoute: () => NestedDotjsRoute, } as any) +const NestedDotjsScriptDotjsRoute = NestedDotjsScriptDotjsRouteImport.update({ + id: '/script.js', + path: '/script.js', + getParentRoute: () => NestedDotjsRoute, +} as any) export interface FileRoutesByFullPath { '/nested.js': typeof NestedDotjsRouteWithChildren @@ -83,13 +83,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/script.js': { - id: '/script.js' - path: '/script.js' - fullPath: '/script.js' - preLoaderRoute: typeof ScriptDotjsRouteImport - parentRoute: typeof rootRouteImport - } '/nested.js': { id: '/nested.js' path: '/nested.js' @@ -97,12 +90,12 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof NestedDotjsRouteImport parentRoute: typeof rootRouteImport } - '/nested.js/script.js': { - id: '/nested.js/script.js' + '/script.js': { + id: '/script.js' path: '/script.js' - fullPath: '/nested.js/script.js' - preLoaderRoute: typeof NestedDotjsScriptDotjsRouteImport - parentRoute: typeof NestedDotjsRoute + fullPath: '/script.js' + preLoaderRoute: typeof ScriptDotjsRouteImport + parentRoute: typeof rootRouteImport } '/nested.js/double.ext.js': { id: '/nested.js/double.ext.js' @@ -111,6 +104,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof NestedDotjsDoubleDotextDotjsRouteImport parentRoute: typeof NestedDotjsRoute } + '/nested.js/script.js': { + id: '/nested.js/script.js' + path: '/script.js' + fullPath: '/nested.js/script.js' + preLoaderRoute: typeof NestedDotjsScriptDotjsRouteImport + parentRoute: typeof NestedDotjsRoute + } } } diff --git a/packages/router-generator/tests/generator/escaped-custom-tokens/routeTree.snapshot.ts b/packages/router-generator/tests/generator/escaped-custom-tokens/routeTree.snapshot.ts index e8b7404df9..e7902c671c 100644 --- a/packages/router-generator/tests/generator/escaped-custom-tokens/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/escaped-custom-tokens/routeTree.snapshot.ts @@ -10,8 +10,8 @@ import { Route as rootRouteImport } from './routes/__root' import { Route as Char91_1nd3xChar93RouteImport } from './routes/[_1nd3x]' -import { Route as BlogR0ut3RouteImport } from './routes/blog._r0ut3_' import { Route as R1nd3xRouteImport } from './routes/_1nd3x' +import { Route as BlogR0ut3RouteImport } from './routes/blog._r0ut3_' import { Route as NestedChar91_1nd3xChar93RouteImport } from './routes/nested.[_1nd3x]' import { Route as PostsChar91_r0ut3_Char93RouteImport } from './routes/posts.[_r0ut3_]' @@ -20,16 +20,16 @@ const Char91_1nd3xChar93Route = Char91_1nd3xChar93RouteImport.update({ path: '/_1nd3x', getParentRoute: () => rootRouteImport, } as any) -const BlogR0ut3Route = BlogR0ut3RouteImport.update({ - id: '/blog', - path: '/blog', - getParentRoute: () => rootRouteImport, -} as any) const R1nd3xRoute = R1nd3xRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) +const BlogR0ut3Route = BlogR0ut3RouteImport.update({ + id: '/blog', + path: '/blog', + getParentRoute: () => rootRouteImport, +} as any) const NestedChar91_1nd3xChar93Route = NestedChar91_1nd3xChar93RouteImport.update({ id: '/nested/_1nd3x', @@ -96,13 +96,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof Char91_1nd3xChar93RouteImport parentRoute: typeof rootRouteImport } - '/blog': { - id: '/blog' - path: '/blog' - fullPath: '/blog' - preLoaderRoute: typeof BlogR0ut3RouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -110,6 +103,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof R1nd3xRouteImport parentRoute: typeof rootRouteImport } + '/blog': { + id: '/blog' + path: '/blog' + fullPath: '/blog' + preLoaderRoute: typeof BlogR0ut3RouteImport + parentRoute: typeof rootRouteImport + } '/nested/_1nd3x': { id: '/nested/_1nd3x' path: '/nested/_1nd3x' diff --git a/packages/router-generator/tests/generator/escaped-special-strings/routeTree.snapshot.ts b/packages/router-generator/tests/generator/escaped-special-strings/routeTree.snapshot.ts index ea71d9c21b..2600d0296d 100644 --- a/packages/router-generator/tests/generator/escaped-special-strings/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/escaped-special-strings/routeTree.snapshot.ts @@ -10,15 +10,15 @@ import { Route as rootRouteImport } from './routes/__root' import { Route as Char91indexChar93RouteImport } from './routes/[index]' -import { Route as Char91routeChar93RouteImport } from './routes/[route]' -import { Route as Char91lazyChar93RouteImport } from './routes/[lazy]' -import { Route as Foo_barRouteImport } from './routes/foo[_]bar' -import { Route as BlogRouteImport } from './routes/blog[_]' -import { Route as Api_v2_usersRouteImport } from './routes/api[_]v2[_]users' -import { Route as Prefix_middle_suffixRouteImport } from './routes/[_]prefix[_]middle[_]suffix' -import { Route as LayoutRouteImport } from './routes/[_]layout' -import { Route as AuthRouteRouteImport } from './routes/[_]auth.route' import { Route as IndexRouteImport } from './routes/index' +import { Route as AuthRouteRouteImport } from './routes/[_]auth.route' +import { Route as LayoutRouteImport } from './routes/[_]layout' +import { Route as Prefix_middle_suffixRouteImport } from './routes/[_]prefix[_]middle[_]suffix' +import { Route as Api_v2_usersRouteImport } from './routes/api[_]v2[_]users' +import { Route as BlogRouteImport } from './routes/blog[_]' +import { Route as Foo_barRouteImport } from './routes/foo[_]bar' +import { Route as Char91lazyChar93RouteImport } from './routes/[lazy]' +import { Route as Char91routeChar93RouteImport } from './routes/[route]' import { Route as NestedChar91indexChar93RouteImport } from './routes/nested.[index]' const Char91indexChar93Route = Char91indexChar93RouteImport.update({ @@ -26,24 +26,24 @@ const Char91indexChar93Route = Char91indexChar93RouteImport.update({ path: '/index', getParentRoute: () => rootRouteImport, } as any) -const Char91routeChar93Route = Char91routeChar93RouteImport.update({ - id: '/route', - path: '/route', +const IndexRoute = IndexRouteImport.update({ + id: '/', + path: '/', getParentRoute: () => rootRouteImport, } as any) -const Char91lazyChar93Route = Char91lazyChar93RouteImport.update({ - id: '/lazy', - path: '/lazy', +const AuthRouteRoute = AuthRouteRouteImport.update({ + id: '/_auth', + path: '/_auth', getParentRoute: () => rootRouteImport, } as any) -const Foo_barRoute = Foo_barRouteImport.update({ - id: '/foo_bar', - path: '/foo_bar', +const LayoutRoute = LayoutRouteImport.update({ + id: '/_layout', + path: '/_layout', getParentRoute: () => rootRouteImport, } as any) -const BlogRoute = BlogRouteImport.update({ - id: '/blog_', - path: '/blog_', +const Prefix_middle_suffixRoute = Prefix_middle_suffixRouteImport.update({ + id: '/_prefix_middle_suffix', + path: '/_prefix_middle_suffix', getParentRoute: () => rootRouteImport, } as any) const Api_v2_usersRoute = Api_v2_usersRouteImport.update({ @@ -51,24 +51,24 @@ const Api_v2_usersRoute = Api_v2_usersRouteImport.update({ path: '/api_v2_users', getParentRoute: () => rootRouteImport, } as any) -const Prefix_middle_suffixRoute = Prefix_middle_suffixRouteImport.update({ - id: '/_prefix_middle_suffix', - path: '/_prefix_middle_suffix', +const BlogRoute = BlogRouteImport.update({ + id: '/blog_', + path: '/blog_', getParentRoute: () => rootRouteImport, } as any) -const LayoutRoute = LayoutRouteImport.update({ - id: '/_layout', - path: '/_layout', +const Foo_barRoute = Foo_barRouteImport.update({ + id: '/foo_bar', + path: '/foo_bar', getParentRoute: () => rootRouteImport, } as any) -const AuthRouteRoute = AuthRouteRouteImport.update({ - id: '/_auth', - path: '/_auth', +const Char91lazyChar93Route = Char91lazyChar93RouteImport.update({ + id: '/lazy', + path: '/lazy', getParentRoute: () => rootRouteImport, } as any) -const IndexRoute = IndexRouteImport.update({ - id: '/', - path: '/', +const Char91routeChar93Route = Char91routeChar93RouteImport.update({ + id: '/route', + path: '/route', getParentRoute: () => rootRouteImport, } as any) const NestedChar91indexChar93Route = NestedChar91indexChar93RouteImport.update({ @@ -182,32 +182,32 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof Char91indexChar93RouteImport parentRoute: typeof rootRouteImport } - '/route': { - id: '/route' - path: '/route' - fullPath: '/route' - preLoaderRoute: typeof Char91routeChar93RouteImport + '/': { + id: '/' + path: '/' + fullPath: '/' + preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } - '/lazy': { - id: '/lazy' - path: '/lazy' - fullPath: '/lazy' - preLoaderRoute: typeof Char91lazyChar93RouteImport + '/_auth': { + id: '/_auth' + path: '/_auth' + fullPath: '/_auth' + preLoaderRoute: typeof AuthRouteRouteImport parentRoute: typeof rootRouteImport } - '/foo_bar': { - id: '/foo_bar' - path: '/foo_bar' - fullPath: '/foo_bar' - preLoaderRoute: typeof Foo_barRouteImport + '/_layout': { + id: '/_layout' + path: '/_layout' + fullPath: '/_layout' + preLoaderRoute: typeof LayoutRouteImport parentRoute: typeof rootRouteImport } - '/blog_': { - id: '/blog_' - path: '/blog_' - fullPath: '/blog_' - preLoaderRoute: typeof BlogRouteImport + '/_prefix_middle_suffix': { + id: '/_prefix_middle_suffix' + path: '/_prefix_middle_suffix' + fullPath: '/_prefix_middle_suffix' + preLoaderRoute: typeof Prefix_middle_suffixRouteImport parentRoute: typeof rootRouteImport } '/api_v2_users': { @@ -217,32 +217,32 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof Api_v2_usersRouteImport parentRoute: typeof rootRouteImport } - '/_prefix_middle_suffix': { - id: '/_prefix_middle_suffix' - path: '/_prefix_middle_suffix' - fullPath: '/_prefix_middle_suffix' - preLoaderRoute: typeof Prefix_middle_suffixRouteImport + '/blog_': { + id: '/blog_' + path: '/blog_' + fullPath: '/blog_' + preLoaderRoute: typeof BlogRouteImport parentRoute: typeof rootRouteImport } - '/_layout': { - id: '/_layout' - path: '/_layout' - fullPath: '/_layout' - preLoaderRoute: typeof LayoutRouteImport + '/foo_bar': { + id: '/foo_bar' + path: '/foo_bar' + fullPath: '/foo_bar' + preLoaderRoute: typeof Foo_barRouteImport parentRoute: typeof rootRouteImport } - '/_auth': { - id: '/_auth' - path: '/_auth' - fullPath: '/_auth' - preLoaderRoute: typeof AuthRouteRouteImport + '/lazy': { + id: '/lazy' + path: '/lazy' + fullPath: '/lazy' + preLoaderRoute: typeof Char91lazyChar93RouteImport parentRoute: typeof rootRouteImport } - '/': { - id: '/' - path: '/' - fullPath: '/' - preLoaderRoute: typeof IndexRouteImport + '/route': { + id: '/route' + path: '/route' + fullPath: '/route' + preLoaderRoute: typeof Char91routeChar93RouteImport parentRoute: typeof rootRouteImport } '/nested/index': { diff --git a/packages/router-generator/tests/generator/export-variations/routeTree.snapshot.ts b/packages/router-generator/tests/generator/export-variations/routeTree.snapshot.ts index 6362489435..bb251cc516 100644 --- a/packages/router-generator/tests/generator/export-variations/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/export-variations/routeTree.snapshot.ts @@ -9,20 +9,20 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as ExportWithAsRouteImport } from './routes/export-with-as' import { Route as ExportSeparateFromDeclarationRouteImport } from './routes/export-separate-from-declaration' +import { Route as ExportWithAsRouteImport } from './routes/export-with-as' -const ExportWithAsRoute = ExportWithAsRouteImport.update({ - id: '/export-with-as', - path: '/export-with-as', - getParentRoute: () => rootRouteImport, -} as any) const ExportSeparateFromDeclarationRoute = ExportSeparateFromDeclarationRouteImport.update({ id: '/export-separate-from-declaration', path: '/export-separate-from-declaration', getParentRoute: () => rootRouteImport, } as any) +const ExportWithAsRoute = ExportWithAsRouteImport.update({ + id: '/export-with-as', + path: '/export-with-as', + getParentRoute: () => rootRouteImport, +} as any) export interface FileRoutesByFullPath { '/export-separate-from-declaration': typeof ExportSeparateFromDeclarationRoute @@ -52,13 +52,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/export-with-as': { - id: '/export-with-as' - path: '/export-with-as' - fullPath: '/export-with-as' - preLoaderRoute: typeof ExportWithAsRouteImport - parentRoute: typeof rootRouteImport - } '/export-separate-from-declaration': { id: '/export-separate-from-declaration' path: '/export-separate-from-declaration' @@ -66,6 +59,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof ExportSeparateFromDeclarationRouteImport parentRoute: typeof rootRouteImport } + '/export-with-as': { + id: '/export-with-as' + path: '/export-with-as' + fullPath: '/export-with-as' + preLoaderRoute: typeof ExportWithAsRouteImport + parentRoute: typeof rootRouteImport + } } } diff --git a/packages/router-generator/tests/generator/file-modification/routeTree.snapshot.ts b/packages/router-generator/tests/generator/file-modification/routeTree.snapshot.ts index ddcc5ea6d6..7ec8640782 100644 --- a/packages/router-generator/tests/generator/file-modification/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/file-modification/routeTree.snapshot.ts @@ -11,12 +11,12 @@ import { createFileRoute } from '@tanstack/react-router' import { Route as rootRouteImport } from './routes/__root' -import { Route as testTemplateLiteralRouteImport } from './routes/(test)/template-literal' -import { Route as testInitiallyLazyRouteImport } from './routes/(test)/initiallyLazy' -import { Route as testInitiallyEmptyRouteImport } from './routes/(test)/initiallyEmpty' -import { Route as testFooRouteImport } from './routes/(test)/foo' -import { Route as testDuplicateImportRouteImport } from './routes/(test)/duplicate-import' import { Route as testDoubleQuotesRouteImport } from './routes/(test)/double-quotes' +import { Route as testDuplicateImportRouteImport } from './routes/(test)/duplicate-import' +import { Route as testFooRouteImport } from './routes/(test)/foo' +import { Route as testInitiallyEmptyRouteImport } from './routes/(test)/initiallyEmpty' +import { Route as testInitiallyLazyRouteImport } from './routes/(test)/initiallyLazy' +import { Route as testTemplateLiteralRouteImport } from './routes/(test)/template-literal' import { Route as testFooBarRouteImport } from './routes/(test)/foo.bar' const testBarLazyRouteImport = createFileRoute('/(test)/bar')() @@ -28,14 +28,19 @@ const testBarLazyRoute = testBarLazyRouteImport getParentRoute: () => rootRouteImport, } as any) .lazy(() => import('./routes/(test)/bar.lazy').then((d) => d.Route)) -const testTemplateLiteralRoute = testTemplateLiteralRouteImport.update({ - id: '/(test)/template-literal', - path: '/template-literal', +const testDoubleQuotesRoute = testDoubleQuotesRouteImport.update({ + id: '/(test)/double-quotes', + path: '/double-quotes', getParentRoute: () => rootRouteImport, } as any) -const testInitiallyLazyRoute = testInitiallyLazyRouteImport.update({ - id: '/(test)/initiallyLazy', - path: '/initiallyLazy', +const testDuplicateImportRoute = testDuplicateImportRouteImport.update({ + id: '/(test)/duplicate-import', + path: '/duplicate-import', + getParentRoute: () => rootRouteImport, +} as any) +const testFooRoute = testFooRouteImport.update({ + id: '/(test)/foo', + path: '/foo', getParentRoute: () => rootRouteImport, } as any) const testInitiallyEmptyRoute = testInitiallyEmptyRouteImport @@ -47,19 +52,14 @@ const testInitiallyEmptyRoute = testInitiallyEmptyRouteImport .lazy(() => import('./routes/(test)/initiallyEmpty.lazy').then((d) => d.Route), ) -const testFooRoute = testFooRouteImport.update({ - id: '/(test)/foo', - path: '/foo', - getParentRoute: () => rootRouteImport, -} as any) -const testDuplicateImportRoute = testDuplicateImportRouteImport.update({ - id: '/(test)/duplicate-import', - path: '/duplicate-import', +const testInitiallyLazyRoute = testInitiallyLazyRouteImport.update({ + id: '/(test)/initiallyLazy', + path: '/initiallyLazy', getParentRoute: () => rootRouteImport, } as any) -const testDoubleQuotesRoute = testDoubleQuotesRouteImport.update({ - id: '/(test)/double-quotes', - path: '/double-quotes', +const testTemplateLiteralRoute = testTemplateLiteralRouteImport.update({ + id: '/(test)/template-literal', + path: '/template-literal', getParentRoute: () => rootRouteImport, } as any) const testFooBarRoute = testFooBarRouteImport.update({ @@ -151,25 +151,18 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof testBarLazyRouteImport parentRoute: typeof rootRouteImport } - '/(test)/template-literal': { - id: '/(test)/template-literal' - path: '/template-literal' - fullPath: '/template-literal' - preLoaderRoute: typeof testTemplateLiteralRouteImport - parentRoute: typeof rootRouteImport - } - '/(test)/initiallyLazy': { - id: '/(test)/initiallyLazy' - path: '/initiallyLazy' - fullPath: '/initiallyLazy' - preLoaderRoute: typeof testInitiallyLazyRouteImport + '/(test)/double-quotes': { + id: '/(test)/double-quotes' + path: '/double-quotes' + fullPath: '/double-quotes' + preLoaderRoute: typeof testDoubleQuotesRouteImport parentRoute: typeof rootRouteImport } - '/(test)/initiallyEmpty': { - id: '/(test)/initiallyEmpty' - path: '/initiallyEmpty' - fullPath: '/initiallyEmpty' - preLoaderRoute: typeof testInitiallyEmptyRouteImport + '/(test)/duplicate-import': { + id: '/(test)/duplicate-import' + path: '/duplicate-import' + fullPath: '/duplicate-import' + preLoaderRoute: typeof testDuplicateImportRouteImport parentRoute: typeof rootRouteImport } '/(test)/foo': { @@ -179,18 +172,25 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof testFooRouteImport parentRoute: typeof rootRouteImport } - '/(test)/duplicate-import': { - id: '/(test)/duplicate-import' - path: '/duplicate-import' - fullPath: '/duplicate-import' - preLoaderRoute: typeof testDuplicateImportRouteImport + '/(test)/initiallyEmpty': { + id: '/(test)/initiallyEmpty' + path: '/initiallyEmpty' + fullPath: '/initiallyEmpty' + preLoaderRoute: typeof testInitiallyEmptyRouteImport parentRoute: typeof rootRouteImport } - '/(test)/double-quotes': { - id: '/(test)/double-quotes' - path: '/double-quotes' - fullPath: '/double-quotes' - preLoaderRoute: typeof testDoubleQuotesRouteImport + '/(test)/initiallyLazy': { + id: '/(test)/initiallyLazy' + path: '/initiallyLazy' + fullPath: '/initiallyLazy' + preLoaderRoute: typeof testInitiallyLazyRouteImport + parentRoute: typeof rootRouteImport + } + '/(test)/template-literal': { + id: '/(test)/template-literal' + path: '/template-literal' + fullPath: '/template-literal' + preLoaderRoute: typeof testTemplateLiteralRouteImport parentRoute: typeof rootRouteImport } '/(test)/foo/bar': { diff --git a/packages/router-generator/tests/generator/flat-route-group/routeTree.snapshot.ts b/packages/router-generator/tests/generator/flat-route-group/routeTree.snapshot.ts index 7f7990e787..ca3cf2f2b7 100644 --- a/packages/router-generator/tests/generator/flat-route-group/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/flat-route-group/routeTree.snapshot.ts @@ -10,8 +10,8 @@ import { Route as rootRouteImport } from './routes/__root' import { Route as AppRouteImport } from './routes/app' -import { Route as AppcomprasComprasOrdenesRouteImport } from './routes/app.(compras)/compras_.ordenes' import { Route as AppcomprasCompras_masRouteImport } from './routes/app.(compras)/compras_._mas' +import { Route as AppcomprasComprasOrdenesRouteImport } from './routes/app.(compras)/compras_.ordenes' import { Route as AppcomprasCompras_masDivisionesRouteImport } from './routes/app.(compras)/compras_._mas.divisiones' const AppRoute = AppRouteImport.update({ @@ -19,17 +19,17 @@ const AppRoute = AppRouteImport.update({ path: '/app', getParentRoute: () => rootRouteImport, } as any) +const AppcomprasCompras_masRoute = AppcomprasCompras_masRouteImport.update({ + id: '/(compras)/compras_/_mas', + path: '/compras', + getParentRoute: () => AppRoute, +} as any) const AppcomprasComprasOrdenesRoute = AppcomprasComprasOrdenesRouteImport.update({ id: '/(compras)/compras_/ordenes', path: '/compras/ordenes', getParentRoute: () => AppRoute, } as any) -const AppcomprasCompras_masRoute = AppcomprasCompras_masRouteImport.update({ - id: '/(compras)/compras_/_mas', - path: '/compras', - getParentRoute: () => AppRoute, -} as any) const AppcomprasCompras_masDivisionesRoute = AppcomprasCompras_masDivisionesRouteImport.update({ id: '/divisiones', @@ -90,13 +90,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof AppRouteImport parentRoute: typeof rootRouteImport } - '/app/(compras)/compras_/ordenes': { - id: '/app/(compras)/compras_/ordenes' - path: '/compras/ordenes' - fullPath: '/app/compras/ordenes' - preLoaderRoute: typeof AppcomprasComprasOrdenesRouteImport - parentRoute: typeof AppRoute - } '/app/(compras)/compras_/_mas': { id: '/app/(compras)/compras_/_mas' path: '/compras' @@ -104,6 +97,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof AppcomprasCompras_masRouteImport parentRoute: typeof AppRoute } + '/app/(compras)/compras_/ordenes': { + id: '/app/(compras)/compras_/ordenes' + path: '/compras/ordenes' + fullPath: '/app/compras/ordenes' + preLoaderRoute: typeof AppcomprasComprasOrdenesRouteImport + parentRoute: typeof AppRoute + } '/app/(compras)/compras_/_mas/divisiones': { id: '/app/(compras)/compras_/_mas/divisiones' path: '/divisiones' diff --git a/packages/router-generator/tests/generator/flat/routeTree.snapshot.ts b/packages/router-generator/tests/generator/flat/routeTree.snapshot.ts index b1bf6587fc..923cfc0530 100644 --- a/packages/router-generator/tests/generator/flat/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/flat/routeTree.snapshot.ts @@ -9,23 +9,23 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as PostsRouteRouteImport } from './routes/posts.route' -import { Route as BlogRouteRouteImport } from './routes/blog.route' import { Route as IndexRouteImport } from './routes/index' -import { Route as PostsIndexRouteImport } from './routes/posts.index' +import { Route as BlogRouteRouteImport } from './routes/blog.route' +import { Route as PostsRouteRouteImport } from './routes/posts.route' import { Route as BlogIndexRouteImport } from './routes/blog.index' -import { Route as BlogStatsRouteImport } from './routes/blog_.stats' import { Route as BlogBlogIdRouteRouteImport } from './routes/blog_.$blogId.route' -import { Route as PostsPostIdIndexRouteImport } from './routes/posts.$postId.index' +import { Route as BlogStatsRouteImport } from './routes/blog_.stats' +import { Route as PostsIndexRouteImport } from './routes/posts.index' import { Route as BlogSlugIndexRouteImport } from './routes/blog.$slug.index' -import { Route as PostsPostIdDeepRouteImport } from './routes/posts.$postId.deep' -import { Route as BlogBlogIdEditRouteImport } from './routes/blog_.$blogId_.edit' import { Route as BlogBlogIdSlugRouteRouteImport } from './routes/blog_.$blogId.$slug.route' +import { Route as BlogBlogIdEditRouteImport } from './routes/blog_.$blogId_.edit' +import { Route as PostsPostIdIndexRouteImport } from './routes/posts.$postId.index' +import { Route as PostsPostIdDeepRouteImport } from './routes/posts.$postId.deep' import { Route as BlogBlogIdSlugBarRouteImport } from './routes/blog_.$blogId.$slug_.bar' -const PostsRouteRoute = PostsRouteRouteImport.update({ - id: '/posts', - path: '/posts', +const IndexRoute = IndexRouteImport.update({ + id: '/', + path: '/', getParentRoute: () => rootRouteImport, } as any) const BlogRouteRoute = BlogRouteRouteImport.update({ @@ -33,34 +33,29 @@ const BlogRouteRoute = BlogRouteRouteImport.update({ path: '/blog', getParentRoute: () => rootRouteImport, } as any) -const IndexRoute = IndexRouteImport.update({ - id: '/', - path: '/', +const PostsRouteRoute = PostsRouteRouteImport.update({ + id: '/posts', + path: '/posts', getParentRoute: () => rootRouteImport, } as any) -const PostsIndexRoute = PostsIndexRouteImport.update({ - id: '/', - path: '/', - getParentRoute: () => PostsRouteRoute, -} as any) const BlogIndexRoute = BlogIndexRouteImport.update({ id: '/', path: '/', getParentRoute: () => BlogRouteRoute, } as any) -const BlogStatsRoute = BlogStatsRouteImport.update({ - id: '/blog_/stats', - path: '/blog/stats', - getParentRoute: () => rootRouteImport, -} as any) const BlogBlogIdRouteRoute = BlogBlogIdRouteRouteImport.update({ id: '/blog_/$blogId', path: '/blog/$blogId', getParentRoute: () => rootRouteImport, } as any) -const PostsPostIdIndexRoute = PostsPostIdIndexRouteImport.update({ - id: '/$postId/', - path: '/$postId/', +const BlogStatsRoute = BlogStatsRouteImport.update({ + id: '/blog_/stats', + path: '/blog/stats', + getParentRoute: () => rootRouteImport, +} as any) +const PostsIndexRoute = PostsIndexRouteImport.update({ + id: '/', + path: '/', getParentRoute: () => PostsRouteRoute, } as any) const BlogSlugIndexRoute = BlogSlugIndexRouteImport.update({ @@ -68,20 +63,25 @@ const BlogSlugIndexRoute = BlogSlugIndexRouteImport.update({ path: '/$slug/', getParentRoute: () => BlogRouteRoute, } as any) -const PostsPostIdDeepRoute = PostsPostIdDeepRouteImport.update({ - id: '/$postId/deep', - path: '/$postId/deep', - getParentRoute: () => PostsRouteRoute, +const BlogBlogIdSlugRouteRoute = BlogBlogIdSlugRouteRouteImport.update({ + id: '/$slug', + path: '/$slug', + getParentRoute: () => BlogBlogIdRouteRoute, } as any) const BlogBlogIdEditRoute = BlogBlogIdEditRouteImport.update({ id: '/blog_/$blogId_/edit', path: '/blog/$blogId/edit', getParentRoute: () => rootRouteImport, } as any) -const BlogBlogIdSlugRouteRoute = BlogBlogIdSlugRouteRouteImport.update({ - id: '/$slug', - path: '/$slug', - getParentRoute: () => BlogBlogIdRouteRoute, +const PostsPostIdIndexRoute = PostsPostIdIndexRouteImport.update({ + id: '/$postId/', + path: '/$postId/', + getParentRoute: () => PostsRouteRoute, +} as any) +const PostsPostIdDeepRoute = PostsPostIdDeepRouteImport.update({ + id: '/$postId/deep', + path: '/$postId/deep', + getParentRoute: () => PostsRouteRoute, } as any) const BlogBlogIdSlugBarRoute = BlogBlogIdSlugBarRouteImport.update({ id: '/$slug_/bar', @@ -190,11 +190,11 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/posts': { - id: '/posts' - path: '/posts' - fullPath: '/posts' - preLoaderRoute: typeof PostsRouteRouteImport + '/': { + id: '/' + path: '/' + fullPath: '/' + preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } '/blog': { @@ -204,20 +204,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof BlogRouteRouteImport parentRoute: typeof rootRouteImport } - '/': { - id: '/' - path: '/' - fullPath: '/' - preLoaderRoute: typeof IndexRouteImport + '/posts': { + id: '/posts' + path: '/posts' + fullPath: '/posts' + preLoaderRoute: typeof PostsRouteRouteImport parentRoute: typeof rootRouteImport } - '/posts/': { - id: '/posts/' - path: '/' - fullPath: '/posts/' - preLoaderRoute: typeof PostsIndexRouteImport - parentRoute: typeof PostsRouteRoute - } '/blog/': { id: '/blog/' path: '/' @@ -225,13 +218,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof BlogIndexRouteImport parentRoute: typeof BlogRouteRoute } - '/blog_/stats': { - id: '/blog_/stats' - path: '/blog/stats' - fullPath: '/blog/stats' - preLoaderRoute: typeof BlogStatsRouteImport - parentRoute: typeof rootRouteImport - } '/blog_/$blogId': { id: '/blog_/$blogId' path: '/blog/$blogId' @@ -239,11 +225,18 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof BlogBlogIdRouteRouteImport parentRoute: typeof rootRouteImport } - '/posts/$postId/': { - id: '/posts/$postId/' - path: '/$postId' - fullPath: '/posts/$postId/' - preLoaderRoute: typeof PostsPostIdIndexRouteImport + '/blog_/stats': { + id: '/blog_/stats' + path: '/blog/stats' + fullPath: '/blog/stats' + preLoaderRoute: typeof BlogStatsRouteImport + parentRoute: typeof rootRouteImport + } + '/posts/': { + id: '/posts/' + path: '/' + fullPath: '/posts/' + preLoaderRoute: typeof PostsIndexRouteImport parentRoute: typeof PostsRouteRoute } '/blog/$slug/': { @@ -253,12 +246,12 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof BlogSlugIndexRouteImport parentRoute: typeof BlogRouteRoute } - '/posts/$postId/deep': { - id: '/posts/$postId/deep' - path: '/$postId/deep' - fullPath: '/posts/$postId/deep' - preLoaderRoute: typeof PostsPostIdDeepRouteImport - parentRoute: typeof PostsRouteRoute + '/blog_/$blogId/$slug': { + id: '/blog_/$blogId/$slug' + path: '/$slug' + fullPath: '/blog/$blogId/$slug' + preLoaderRoute: typeof BlogBlogIdSlugRouteRouteImport + parentRoute: typeof BlogBlogIdRouteRoute } '/blog_/$blogId_/edit': { id: '/blog_/$blogId_/edit' @@ -267,12 +260,19 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof BlogBlogIdEditRouteImport parentRoute: typeof rootRouteImport } - '/blog_/$blogId/$slug': { - id: '/blog_/$blogId/$slug' - path: '/$slug' - fullPath: '/blog/$blogId/$slug' - preLoaderRoute: typeof BlogBlogIdSlugRouteRouteImport - parentRoute: typeof BlogBlogIdRouteRoute + '/posts/$postId/': { + id: '/posts/$postId/' + path: '/$postId' + fullPath: '/posts/$postId/' + preLoaderRoute: typeof PostsPostIdIndexRouteImport + parentRoute: typeof PostsRouteRoute + } + '/posts/$postId/deep': { + id: '/posts/$postId/deep' + path: '/$postId/deep' + fullPath: '/posts/$postId/deep' + preLoaderRoute: typeof PostsPostIdDeepRouteImport + parentRoute: typeof PostsRouteRoute } '/blog_/$blogId/$slug_/bar': { id: '/blog_/$blogId/$slug_/bar' diff --git a/packages/router-generator/tests/generator/invalid-param-names/routeTree.snapshot.ts b/packages/router-generator/tests/generator/invalid-param-names/routeTree.snapshot.ts index 4728dd439e..9048976e40 100644 --- a/packages/router-generator/tests/generator/invalid-param-names/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/invalid-param-names/routeTree.snapshot.ts @@ -9,13 +9,13 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as ValidParamRouteImport } from './routes/$validParam' -import { Route as UserNameRouteImport } from './routes/$user-name' import { Route as R123RouteImport } from './routes/$123' +import { Route as UserNameRouteImport } from './routes/$user-name' +import { Route as ValidParamRouteImport } from './routes/$validParam' -const ValidParamRoute = ValidParamRouteImport.update({ - id: '/$validParam', - path: '/$validParam', +const R123Route = R123RouteImport.update({ + id: '/$123', + path: '/$123', getParentRoute: () => rootRouteImport, } as any) const UserNameRoute = UserNameRouteImport.update({ @@ -23,9 +23,9 @@ const UserNameRoute = UserNameRouteImport.update({ path: '/$user-name', getParentRoute: () => rootRouteImport, } as any) -const R123Route = R123RouteImport.update({ - id: '/$123', - path: '/$123', +const ValidParamRoute = ValidParamRouteImport.update({ + id: '/$validParam', + path: '/$validParam', getParentRoute: () => rootRouteImport, } as any) @@ -61,11 +61,11 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/$validParam': { - id: '/$validParam' - path: '/$validParam' - fullPath: '/$validParam' - preLoaderRoute: typeof ValidParamRouteImport + '/$123': { + id: '/$123' + path: '/$123' + fullPath: '/$123' + preLoaderRoute: typeof R123RouteImport parentRoute: typeof rootRouteImport } '/$user-name': { @@ -75,11 +75,11 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof UserNameRouteImport parentRoute: typeof rootRouteImport } - '/$123': { - id: '/$123' - path: '/$123' - fullPath: '/$123' - preLoaderRoute: typeof R123RouteImport + '/$validParam': { + id: '/$validParam' + path: '/$validParam' + fullPath: '/$validParam' + preLoaderRoute: typeof ValidParamRouteImport parentRoute: typeof rootRouteImport } } 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 d99745d928..7fb6ebb0d0 100644 --- a/packages/router-generator/tests/generator/nested-layouts/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/nested-layouts/routeTree.snapshot.ts @@ -9,141 +9,141 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as LayoutA2RouteImport } from './routes/_layout-a2' +import { Route as IndexRouteImport } from './routes/index' import { Route as LayoutA1RouteImport } from './routes/_layout-a1' +import { Route as LayoutA2RouteImport } from './routes/_layout-a2' import { Route as JestedRouteRouteImport } from './routes/jested/route' -import { Route as IndexRouteImport } from './routes/index' -import { Route as NestedLayoutB2RouteImport } from './routes/nested/_layout-b2' -import { Route as NestedLayoutB1RouteImport } from './routes/nested/_layout-b1' -import { Route as JestedLayoutB4RouteImport } from './routes/jested/_layout-b4' -import { Route as JestedLayoutB3RouteImport } from './routes/jested/_layout-b3' -import { Route as FooBarRouteImport } from './routes/foo/bar' -import { Route as LayoutA2BarRouteImport } from './routes/_layout-a2/bar' -import { Route as LayoutA1FooRouteImport } from './routes/_layout-a1/foo' import { Route as folderInFolderRouteImport } from './routes/(folder)/in-folder' +import { Route as LayoutA1FooRouteImport } from './routes/_layout-a1/foo' +import { Route as LayoutA2BarRouteImport } from './routes/_layout-a2/bar' import { Route as FooLayoutB5RouteRouteImport } from './routes/foo/_layout-b5/route' -import { Route as NestedLayoutB1IndexRouteImport } from './routes/nested/_layout-b1/index' -import { Route as JestedLayoutB3IndexRouteImport } from './routes/jested/_layout-b3/index' +import { Route as FooBarRouteImport } from './routes/foo/bar' +import { Route as JestedLayoutB3RouteImport } from './routes/jested/_layout-b3' +import { Route as JestedLayoutB4RouteImport } from './routes/jested/_layout-b4' +import { Route as NestedLayoutB1RouteImport } from './routes/nested/_layout-b1' +import { Route as NestedLayoutB2RouteImport } from './routes/nested/_layout-b2' import { Route as FooLayoutB5IndexRouteImport } from './routes/foo/_layout-b5/index' -import { Route as NestedLayoutB2FooRouteImport } from './routes/nested/_layout-b2/foo' -import { Route as NestedLayoutB1LayoutC1RouteImport } from './routes/nested/_layout-b1/_layout-c1' -import { Route as JestedLayoutB4FooRouteImport } from './routes/jested/_layout-b4/foo' -import { Route as JestedLayoutB3LayoutC2RouteImport } from './routes/jested/_layout-b3/_layout-c2' import { Route as FooLayoutB5IdRouteImport } from './routes/foo/_layout-b5/$id' -import { Route as NestedLayoutB1LayoutC1BarRouteImport } from './routes/nested/_layout-b1/_layout-c1/bar' +import { Route as JestedLayoutB3IndexRouteImport } from './routes/jested/_layout-b3/index' +import { Route as JestedLayoutB3LayoutC2RouteImport } from './routes/jested/_layout-b3/_layout-c2' +import { Route as JestedLayoutB4FooRouteImport } from './routes/jested/_layout-b4/foo' +import { Route as NestedLayoutB1IndexRouteImport } from './routes/nested/_layout-b1/index' +import { Route as NestedLayoutB1LayoutC1RouteImport } from './routes/nested/_layout-b1/_layout-c1' +import { Route as NestedLayoutB2FooRouteImport } from './routes/nested/_layout-b2/foo' import { Route as JestedLayoutB3LayoutC2BarRouteImport } from './routes/jested/_layout-b3/_layout-c2/bar' +import { Route as NestedLayoutB1LayoutC1BarRouteImport } from './routes/nested/_layout-b1/_layout-c1/bar' -const LayoutA2Route = LayoutA2RouteImport.update({ - id: '/_layout-a2', +const IndexRoute = IndexRouteImport.update({ + id: '/', + path: '/', getParentRoute: () => rootRouteImport, } as any) const LayoutA1Route = LayoutA1RouteImport.update({ id: '/_layout-a1', getParentRoute: () => rootRouteImport, } as any) +const LayoutA2Route = LayoutA2RouteImport.update({ + id: '/_layout-a2', + getParentRoute: () => rootRouteImport, +} as any) const JestedRouteRoute = JestedRouteRouteImport.update({ id: '/jested', path: '/jested', getParentRoute: () => rootRouteImport, } as any) -const IndexRoute = IndexRouteImport.update({ - id: '/', - path: '/', - getParentRoute: () => rootRouteImport, -} as any) -const NestedLayoutB2Route = NestedLayoutB2RouteImport.update({ - id: '/nested/_layout-b2', - path: '/nested', +const folderInFolderRoute = folderInFolderRouteImport.update({ + id: '/(folder)/in-folder', + path: '/in-folder', getParentRoute: () => rootRouteImport, } as any) -const NestedLayoutB1Route = NestedLayoutB1RouteImport.update({ - id: '/nested/_layout-b1', - path: '/nested', - getParentRoute: () => rootRouteImport, +const LayoutA1FooRoute = LayoutA1FooRouteImport.update({ + id: '/foo', + path: '/foo', + getParentRoute: () => LayoutA1Route, } as any) -const JestedLayoutB4Route = JestedLayoutB4RouteImport.update({ - id: '/_layout-b4', - getParentRoute: () => JestedRouteRoute, +const LayoutA2BarRoute = LayoutA2BarRouteImport.update({ + id: '/bar', + path: '/bar', + getParentRoute: () => LayoutA2Route, } as any) -const JestedLayoutB3Route = JestedLayoutB3RouteImport.update({ - id: '/_layout-b3', - getParentRoute: () => JestedRouteRoute, +const FooLayoutB5RouteRoute = FooLayoutB5RouteRouteImport.update({ + id: '/foo/_layout-b5', + path: '/foo', + getParentRoute: () => rootRouteImport, } as any) const FooBarRoute = FooBarRouteImport.update({ id: '/foo/bar', path: '/foo/bar', getParentRoute: () => rootRouteImport, } as any) -const LayoutA2BarRoute = LayoutA2BarRouteImport.update({ - id: '/bar', - path: '/bar', - getParentRoute: () => LayoutA2Route, +const JestedLayoutB3Route = JestedLayoutB3RouteImport.update({ + id: '/_layout-b3', + getParentRoute: () => JestedRouteRoute, } as any) -const LayoutA1FooRoute = LayoutA1FooRouteImport.update({ - id: '/foo', - path: '/foo', - getParentRoute: () => LayoutA1Route, +const JestedLayoutB4Route = JestedLayoutB4RouteImport.update({ + id: '/_layout-b4', + getParentRoute: () => JestedRouteRoute, } as any) -const folderInFolderRoute = folderInFolderRouteImport.update({ - id: '/(folder)/in-folder', - path: '/in-folder', +const NestedLayoutB1Route = NestedLayoutB1RouteImport.update({ + id: '/nested/_layout-b1', + path: '/nested', getParentRoute: () => rootRouteImport, } as any) -const FooLayoutB5RouteRoute = FooLayoutB5RouteRouteImport.update({ - id: '/foo/_layout-b5', - path: '/foo', +const NestedLayoutB2Route = NestedLayoutB2RouteImport.update({ + id: '/nested/_layout-b2', + path: '/nested', getParentRoute: () => rootRouteImport, } as any) -const NestedLayoutB1IndexRoute = NestedLayoutB1IndexRouteImport.update({ +const FooLayoutB5IndexRoute = FooLayoutB5IndexRouteImport.update({ id: '/', path: '/', - getParentRoute: () => NestedLayoutB1Route, + getParentRoute: () => FooLayoutB5RouteRoute, +} as any) +const FooLayoutB5IdRoute = FooLayoutB5IdRouteImport.update({ + id: '/$id', + path: '/$id', + getParentRoute: () => FooLayoutB5RouteRoute, } as any) const JestedLayoutB3IndexRoute = JestedLayoutB3IndexRouteImport.update({ id: '/', path: '/', getParentRoute: () => JestedLayoutB3Route, } as any) -const FooLayoutB5IndexRoute = FooLayoutB5IndexRouteImport.update({ - id: '/', - path: '/', - getParentRoute: () => FooLayoutB5RouteRoute, +const JestedLayoutB3LayoutC2Route = JestedLayoutB3LayoutC2RouteImport.update({ + id: '/_layout-c2', + getParentRoute: () => JestedLayoutB3Route, } as any) -const NestedLayoutB2FooRoute = NestedLayoutB2FooRouteImport.update({ +const JestedLayoutB4FooRoute = JestedLayoutB4FooRouteImport.update({ id: '/foo', path: '/foo', - getParentRoute: () => NestedLayoutB2Route, + getParentRoute: () => JestedLayoutB4Route, +} as any) +const NestedLayoutB1IndexRoute = NestedLayoutB1IndexRouteImport.update({ + id: '/', + path: '/', + getParentRoute: () => NestedLayoutB1Route, } as any) const NestedLayoutB1LayoutC1Route = NestedLayoutB1LayoutC1RouteImport.update({ id: '/_layout-c1', getParentRoute: () => NestedLayoutB1Route, } as any) -const JestedLayoutB4FooRoute = JestedLayoutB4FooRouteImport.update({ +const NestedLayoutB2FooRoute = NestedLayoutB2FooRouteImport.update({ id: '/foo', path: '/foo', - getParentRoute: () => JestedLayoutB4Route, -} as any) -const JestedLayoutB3LayoutC2Route = JestedLayoutB3LayoutC2RouteImport.update({ - id: '/_layout-c2', - getParentRoute: () => JestedLayoutB3Route, -} as any) -const FooLayoutB5IdRoute = FooLayoutB5IdRouteImport.update({ - id: '/$id', - path: '/$id', - getParentRoute: () => FooLayoutB5RouteRoute, + getParentRoute: () => NestedLayoutB2Route, } as any) -const NestedLayoutB1LayoutC1BarRoute = - NestedLayoutB1LayoutC1BarRouteImport.update({ - id: '/bar', - path: '/bar', - getParentRoute: () => NestedLayoutB1LayoutC1Route, - } as any) const JestedLayoutB3LayoutC2BarRoute = JestedLayoutB3LayoutC2BarRouteImport.update({ id: '/bar', path: '/bar', getParentRoute: () => JestedLayoutB3LayoutC2Route, } as any) +const NestedLayoutB1LayoutC1BarRoute = + NestedLayoutB1LayoutC1BarRouteImport.update({ + id: '/bar', + path: '/bar', + getParentRoute: () => NestedLayoutB1LayoutC1Route, + } as any) export interface FileRoutesByFullPath { '/': typeof IndexRoute @@ -275,11 +275,11 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/_layout-a2': { - id: '/_layout-a2' - path: '' + '/': { + id: '/' + path: '/' fullPath: '/' - preLoaderRoute: typeof LayoutA2RouteImport + preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } '/_layout-a1': { @@ -289,6 +289,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof LayoutA1RouteImport parentRoute: typeof rootRouteImport } + '/_layout-a2': { + id: '/_layout-a2' + path: '' + fullPath: '/' + preLoaderRoute: typeof LayoutA2RouteImport + parentRoute: typeof rootRouteImport + } '/jested': { id: '/jested' path: '/jested' @@ -296,40 +303,33 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof JestedRouteRouteImport parentRoute: typeof rootRouteImport } - '/': { - id: '/' - path: '/' - fullPath: '/' - preLoaderRoute: typeof IndexRouteImport - parentRoute: typeof rootRouteImport - } - '/nested/_layout-b2': { - id: '/nested/_layout-b2' - path: '/nested' - fullPath: '/nested' - preLoaderRoute: typeof NestedLayoutB2RouteImport + '/(folder)/in-folder': { + id: '/(folder)/in-folder' + path: '/in-folder' + fullPath: '/in-folder' + preLoaderRoute: typeof folderInFolderRouteImport parentRoute: typeof rootRouteImport } - '/nested/_layout-b1': { - id: '/nested/_layout-b1' - path: '/nested' - fullPath: '/nested' - preLoaderRoute: typeof NestedLayoutB1RouteImport - parentRoute: typeof rootRouteImport + '/_layout-a1/foo': { + id: '/_layout-a1/foo' + path: '/foo' + fullPath: '/foo' + preLoaderRoute: typeof LayoutA1FooRouteImport + parentRoute: typeof LayoutA1Route } - '/jested/_layout-b4': { - id: '/jested/_layout-b4' - path: '' - fullPath: '/jested' - preLoaderRoute: typeof JestedLayoutB4RouteImport - parentRoute: typeof JestedRouteRoute + '/_layout-a2/bar': { + id: '/_layout-a2/bar' + path: '/bar' + fullPath: '/bar' + preLoaderRoute: typeof LayoutA2BarRouteImport + parentRoute: typeof LayoutA2Route } - '/jested/_layout-b3': { - id: '/jested/_layout-b3' - path: '' - fullPath: '/jested' - preLoaderRoute: typeof JestedLayoutB3RouteImport - parentRoute: typeof JestedRouteRoute + '/foo/_layout-b5': { + id: '/foo/_layout-b5' + path: '/foo' + fullPath: '/foo' + preLoaderRoute: typeof FooLayoutB5RouteRouteImport + parentRoute: typeof rootRouteImport } '/foo/bar': { id: '/foo/bar' @@ -338,40 +338,47 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof FooBarRouteImport parentRoute: typeof rootRouteImport } - '/_layout-a2/bar': { - id: '/_layout-a2/bar' - path: '/bar' - fullPath: '/bar' - preLoaderRoute: typeof LayoutA2BarRouteImport - parentRoute: typeof LayoutA2Route + '/jested/_layout-b3': { + id: '/jested/_layout-b3' + path: '' + fullPath: '/jested' + preLoaderRoute: typeof JestedLayoutB3RouteImport + parentRoute: typeof JestedRouteRoute } - '/_layout-a1/foo': { - id: '/_layout-a1/foo' - path: '/foo' - fullPath: '/foo' - preLoaderRoute: typeof LayoutA1FooRouteImport - parentRoute: typeof LayoutA1Route + '/jested/_layout-b4': { + id: '/jested/_layout-b4' + path: '' + fullPath: '/jested' + preLoaderRoute: typeof JestedLayoutB4RouteImport + parentRoute: typeof JestedRouteRoute } - '/(folder)/in-folder': { - id: '/(folder)/in-folder' - path: '/in-folder' - fullPath: '/in-folder' - preLoaderRoute: typeof folderInFolderRouteImport + '/nested/_layout-b1': { + id: '/nested/_layout-b1' + path: '/nested' + fullPath: '/nested' + preLoaderRoute: typeof NestedLayoutB1RouteImport parentRoute: typeof rootRouteImport } - '/foo/_layout-b5': { - id: '/foo/_layout-b5' - path: '/foo' - fullPath: '/foo' - preLoaderRoute: typeof FooLayoutB5RouteRouteImport + '/nested/_layout-b2': { + id: '/nested/_layout-b2' + path: '/nested' + fullPath: '/nested' + preLoaderRoute: typeof NestedLayoutB2RouteImport parentRoute: typeof rootRouteImport } - '/nested/_layout-b1/': { - id: '/nested/_layout-b1/' + '/foo/_layout-b5/': { + id: '/foo/_layout-b5/' path: '/' - fullPath: '/nested/' - preLoaderRoute: typeof NestedLayoutB1IndexRouteImport - parentRoute: typeof NestedLayoutB1Route + fullPath: '/foo/' + preLoaderRoute: typeof FooLayoutB5IndexRouteImport + parentRoute: typeof FooLayoutB5RouteRoute + } + '/foo/_layout-b5/$id': { + id: '/foo/_layout-b5/$id' + path: '/$id' + fullPath: '/foo/$id' + preLoaderRoute: typeof FooLayoutB5IdRouteImport + parentRoute: typeof FooLayoutB5RouteRoute } '/jested/_layout-b3/': { id: '/jested/_layout-b3/' @@ -380,19 +387,26 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof JestedLayoutB3IndexRouteImport parentRoute: typeof JestedLayoutB3Route } - '/foo/_layout-b5/': { - id: '/foo/_layout-b5/' - path: '/' - fullPath: '/foo/' - preLoaderRoute: typeof FooLayoutB5IndexRouteImport - parentRoute: typeof FooLayoutB5RouteRoute + '/jested/_layout-b3/_layout-c2': { + id: '/jested/_layout-b3/_layout-c2' + path: '' + fullPath: '/jested' + preLoaderRoute: typeof JestedLayoutB3LayoutC2RouteImport + parentRoute: typeof JestedLayoutB3Route } - '/nested/_layout-b2/foo': { - id: '/nested/_layout-b2/foo' + '/jested/_layout-b4/foo': { + id: '/jested/_layout-b4/foo' path: '/foo' - fullPath: '/nested/foo' - preLoaderRoute: typeof NestedLayoutB2FooRouteImport - parentRoute: typeof NestedLayoutB2Route + fullPath: '/jested/foo' + preLoaderRoute: typeof JestedLayoutB4FooRouteImport + parentRoute: typeof JestedLayoutB4Route + } + '/nested/_layout-b1/': { + id: '/nested/_layout-b1/' + path: '/' + fullPath: '/nested/' + preLoaderRoute: typeof NestedLayoutB1IndexRouteImport + parentRoute: typeof NestedLayoutB1Route } '/nested/_layout-b1/_layout-c1': { id: '/nested/_layout-b1/_layout-c1' @@ -401,26 +415,19 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof NestedLayoutB1LayoutC1RouteImport parentRoute: typeof NestedLayoutB1Route } - '/jested/_layout-b4/foo': { - id: '/jested/_layout-b4/foo' + '/nested/_layout-b2/foo': { + id: '/nested/_layout-b2/foo' path: '/foo' - fullPath: '/jested/foo' - preLoaderRoute: typeof JestedLayoutB4FooRouteImport - parentRoute: typeof JestedLayoutB4Route - } - '/jested/_layout-b3/_layout-c2': { - id: '/jested/_layout-b3/_layout-c2' - path: '' - fullPath: '/jested' - preLoaderRoute: typeof JestedLayoutB3LayoutC2RouteImport - parentRoute: typeof JestedLayoutB3Route + fullPath: '/nested/foo' + preLoaderRoute: typeof NestedLayoutB2FooRouteImport + parentRoute: typeof NestedLayoutB2Route } - '/foo/_layout-b5/$id': { - id: '/foo/_layout-b5/$id' - path: '/$id' - fullPath: '/foo/$id' - preLoaderRoute: typeof FooLayoutB5IdRouteImport - parentRoute: typeof FooLayoutB5RouteRoute + '/jested/_layout-b3/_layout-c2/bar': { + id: '/jested/_layout-b3/_layout-c2/bar' + path: '/bar' + fullPath: '/jested/bar' + preLoaderRoute: typeof JestedLayoutB3LayoutC2BarRouteImport + parentRoute: typeof JestedLayoutB3LayoutC2Route } '/nested/_layout-b1/_layout-c1/bar': { id: '/nested/_layout-b1/_layout-c1/bar' @@ -429,13 +436,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof NestedLayoutB1LayoutC1BarRouteImport parentRoute: typeof NestedLayoutB1LayoutC1Route } - '/jested/_layout-b3/_layout-c2/bar': { - id: '/jested/_layout-b3/_layout-c2/bar' - path: '/bar' - fullPath: '/jested/bar' - preLoaderRoute: typeof JestedLayoutB3LayoutC2BarRouteImport - parentRoute: typeof JestedLayoutB3LayoutC2Route - } } } diff --git a/packages/router-generator/tests/generator/nested-route-groups-with-layouts-before-physical/routeTree.snapshot.ts b/packages/router-generator/tests/generator/nested-route-groups-with-layouts-before-physical/routeTree.snapshot.ts index 6c5c9950b2..8f2741b206 100644 --- a/packages/router-generator/tests/generator/nested-route-groups-with-layouts-before-physical/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/nested-route-groups-with-layouts-before-physical/routeTree.snapshot.ts @@ -9,45 +9,45 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as groupCLayoutCRouteImport } from './routes/(group-c)/_layout-c' -import { Route as groupBLayoutBRouteImport } from './routes/(group-b)/_layout-b' import { Route as groupALayoutARouteImport } from './routes/(group-a)/_layout-a' -import { Route as groupCLayoutCIndexRouteImport } from './routes/(group-c)/_layout-c/index' -import { Route as groupBLayoutBDashboardRouteImport } from './routes/(group-b)/_layout-b/dashboard' -import { Route as groupALayoutASignupRouteImport } from './routes/(group-a)/_layout-a/signup' +import { Route as groupBLayoutBRouteImport } from './routes/(group-b)/_layout-b' +import { Route as groupCLayoutCRouteImport } from './routes/(group-c)/_layout-c' import { Route as groupALayoutALoginRouteImport } from './routes/(group-a)/_layout-a/login' +import { Route as groupALayoutASignupRouteImport } from './routes/(group-a)/_layout-a/signup' +import { Route as groupBLayoutBDashboardRouteImport } from './routes/(group-b)/_layout-b/dashboard' +import { Route as groupCLayoutCIndexRouteImport } from './routes/(group-c)/_layout-c/index' -const groupCLayoutCRoute = groupCLayoutCRouteImport.update({ - id: '/(group-c)/_layout-c', +const groupALayoutARoute = groupALayoutARouteImport.update({ + id: '/(group-a)/_layout-a', getParentRoute: () => rootRouteImport, } as any) const groupBLayoutBRoute = groupBLayoutBRouteImport.update({ id: '/(group-b)/_layout-b', getParentRoute: () => rootRouteImport, } as any) -const groupALayoutARoute = groupALayoutARouteImport.update({ - id: '/(group-a)/_layout-a', +const groupCLayoutCRoute = groupCLayoutCRouteImport.update({ + id: '/(group-c)/_layout-c', getParentRoute: () => rootRouteImport, } as any) -const groupCLayoutCIndexRoute = groupCLayoutCIndexRouteImport.update({ - id: '/', - path: '/', - getParentRoute: () => groupCLayoutCRoute, -} as any) -const groupBLayoutBDashboardRoute = groupBLayoutBDashboardRouteImport.update({ - id: '/dashboard', - path: '/dashboard', - getParentRoute: () => groupBLayoutBRoute, +const groupALayoutALoginRoute = groupALayoutALoginRouteImport.update({ + id: '/login', + path: '/login', + getParentRoute: () => groupALayoutARoute, } as any) const groupALayoutASignupRoute = groupALayoutASignupRouteImport.update({ id: '/signup', path: '/signup', getParentRoute: () => groupALayoutARoute, } as any) -const groupALayoutALoginRoute = groupALayoutALoginRouteImport.update({ - id: '/login', - path: '/login', - getParentRoute: () => groupALayoutARoute, +const groupBLayoutBDashboardRoute = groupBLayoutBDashboardRouteImport.update({ + id: '/dashboard', + path: '/dashboard', + getParentRoute: () => groupBLayoutBRoute, +} as any) +const groupCLayoutCIndexRoute = groupCLayoutCIndexRouteImport.update({ + id: '/', + path: '/', + getParentRoute: () => groupCLayoutCRoute, } as any) export interface FileRoutesByFullPath { @@ -96,11 +96,11 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/(group-c)/_layout-c': { - id: '/(group-c)/_layout-c' + '/(group-a)/_layout-a': { + id: '/(group-a)/_layout-a' path: '' fullPath: '' - preLoaderRoute: typeof groupCLayoutCRouteImport + preLoaderRoute: typeof groupALayoutARouteImport parentRoute: typeof rootRouteImport } '/(group-b)/_layout-b': { @@ -110,26 +110,19 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof groupBLayoutBRouteImport parentRoute: typeof rootRouteImport } - '/(group-a)/_layout-a': { - id: '/(group-a)/_layout-a' + '/(group-c)/_layout-c': { + id: '/(group-c)/_layout-c' path: '' fullPath: '' - preLoaderRoute: typeof groupALayoutARouteImport + preLoaderRoute: typeof groupCLayoutCRouteImport parentRoute: typeof rootRouteImport } - '/(group-c)/_layout-c/': { - id: '/(group-c)/_layout-c/' - path: '/' - fullPath: '/' - preLoaderRoute: typeof groupCLayoutCIndexRouteImport - parentRoute: typeof groupCLayoutCRoute - } - '/(group-b)/_layout-b/dashboard': { - id: '/(group-b)/_layout-b/dashboard' - path: '/dashboard' - fullPath: '/dashboard' - preLoaderRoute: typeof groupBLayoutBDashboardRouteImport - parentRoute: typeof groupBLayoutBRoute + '/(group-a)/_layout-a/login': { + id: '/(group-a)/_layout-a/login' + path: '/login' + fullPath: '/login' + preLoaderRoute: typeof groupALayoutALoginRouteImport + parentRoute: typeof groupALayoutARoute } '/(group-a)/_layout-a/signup': { id: '/(group-a)/_layout-a/signup' @@ -138,12 +131,19 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof groupALayoutASignupRouteImport parentRoute: typeof groupALayoutARoute } - '/(group-a)/_layout-a/login': { - id: '/(group-a)/_layout-a/login' - path: '/login' - fullPath: '/login' - preLoaderRoute: typeof groupALayoutALoginRouteImport - parentRoute: typeof groupALayoutARoute + '/(group-b)/_layout-b/dashboard': { + id: '/(group-b)/_layout-b/dashboard' + path: '/dashboard' + fullPath: '/dashboard' + preLoaderRoute: typeof groupBLayoutBDashboardRouteImport + parentRoute: typeof groupBLayoutBRoute + } + '/(group-c)/_layout-c/': { + id: '/(group-c)/_layout-c/' + path: '/' + fullPath: '/' + preLoaderRoute: typeof groupCLayoutCIndexRouteImport + parentRoute: typeof groupCLayoutCRoute } } } diff --git a/packages/router-generator/tests/generator/nested/routeTree.snapshot.ts b/packages/router-generator/tests/generator/nested/routeTree.snapshot.ts index 9a87dd6953..685b1b29ca 100644 --- a/packages/router-generator/tests/generator/nested/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/nested/routeTree.snapshot.ts @@ -9,29 +9,29 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' +import { Route as IndexRouteImport } from './routes/index' import { Route as PathlessLayoutRouteImport } from './routes/_pathlessLayout' -import { Route as PostsRouteRouteImport } from './routes/posts/route' import { Route as BlogRouteRouteImport } from './routes/blog/route' -import { Route as IndexRouteImport } from './routes/index' -import { Route as PostsIndexRouteImport } from './routes/posts/index' +import { Route as PostsRouteRouteImport } from './routes/posts/route' +import { Route as PathlessLayoutSettingsRouteImport } from './routes/_pathlessLayout/settings' import { Route as BlogIndexRouteImport } from './routes/blog/index' -import { Route as BlogStatsRouteImport } from './routes/blog_/stats' import { Route as BlogSlugRouteImport } from './routes/blog/$slug' -import { Route as PathlessLayoutSettingsRouteImport } from './routes/_pathlessLayout/settings' import { Route as BlogBlogIdRouteRouteImport } from './routes/blog_/$blogId/route' +import { Route as BlogStatsRouteImport } from './routes/blog_/stats' +import { Route as PostsIndexRouteImport } from './routes/posts/index' +import { Route as BlogBlogIdSlugRouteRouteImport } from './routes/blog_/$blogId/$slug/route' +import { Route as BlogBlogIdEditRouteImport } from './routes/blog_/$blogId_/edit' import { Route as PostsPostIdIndexRouteImport } from './routes/posts/$postId/index' import { Route as PostsPostIdDeepRouteImport } from './routes/posts/$postId/deep' -import { Route as BlogBlogIdEditRouteImport } from './routes/blog_/$blogId_/edit' -import { Route as BlogBlogIdSlugRouteRouteImport } from './routes/blog_/$blogId/$slug/route' import { Route as BlogBlogIdSlugBarRouteImport } from './routes/blog_/$blogId/$slug_/bar' -const PathlessLayoutRoute = PathlessLayoutRouteImport.update({ - id: '/_pathlessLayout', +const IndexRoute = IndexRouteImport.update({ + id: '/', + path: '/', getParentRoute: () => rootRouteImport, } as any) -const PostsRouteRoute = PostsRouteRouteImport.update({ - id: '/posts', - path: '/posts', +const PathlessLayoutRoute = PathlessLayoutRouteImport.update({ + id: '/_pathlessLayout', getParentRoute: () => rootRouteImport, } as any) const BlogRouteRoute = BlogRouteRouteImport.update({ @@ -39,41 +39,51 @@ const BlogRouteRoute = BlogRouteRouteImport.update({ path: '/blog', getParentRoute: () => rootRouteImport, } as any) -const IndexRoute = IndexRouteImport.update({ - id: '/', - path: '/', +const PostsRouteRoute = PostsRouteRouteImport.update({ + id: '/posts', + path: '/posts', getParentRoute: () => rootRouteImport, } as any) -const PostsIndexRoute = PostsIndexRouteImport.update({ - id: '/', - path: '/', - getParentRoute: () => PostsRouteRoute, +const PathlessLayoutSettingsRoute = PathlessLayoutSettingsRouteImport.update({ + id: '/settings', + path: '/settings', + getParentRoute: () => PathlessLayoutRoute, } as any) const BlogIndexRoute = BlogIndexRouteImport.update({ id: '/', path: '/', getParentRoute: () => BlogRouteRoute, } as any) -const BlogStatsRoute = BlogStatsRouteImport.update({ - id: '/blog_/stats', - path: '/blog/stats', - getParentRoute: () => rootRouteImport, -} as any) const BlogSlugRoute = BlogSlugRouteImport.update({ id: '/$slug', path: '/$slug', getParentRoute: () => BlogRouteRoute, } as any) -const PathlessLayoutSettingsRoute = PathlessLayoutSettingsRouteImport.update({ - id: '/settings', - path: '/settings', - getParentRoute: () => PathlessLayoutRoute, -} as any) const BlogBlogIdRouteRoute = BlogBlogIdRouteRouteImport.update({ id: '/blog_/$blogId', path: '/blog/$blogId', getParentRoute: () => rootRouteImport, } as any) +const BlogStatsRoute = BlogStatsRouteImport.update({ + id: '/blog_/stats', + path: '/blog/stats', + getParentRoute: () => rootRouteImport, +} as any) +const PostsIndexRoute = PostsIndexRouteImport.update({ + id: '/', + path: '/', + getParentRoute: () => PostsRouteRoute, +} as any) +const BlogBlogIdSlugRouteRoute = BlogBlogIdSlugRouteRouteImport.update({ + id: '/$slug', + path: '/$slug', + getParentRoute: () => BlogBlogIdRouteRoute, +} as any) +const BlogBlogIdEditRoute = BlogBlogIdEditRouteImport.update({ + id: '/blog_/$blogId_/edit', + path: '/blog/$blogId/edit', + getParentRoute: () => rootRouteImport, +} as any) const PostsPostIdIndexRoute = PostsPostIdIndexRouteImport.update({ id: '/$postId/', path: '/$postId/', @@ -84,16 +94,6 @@ const PostsPostIdDeepRoute = PostsPostIdDeepRouteImport.update({ path: '/$postId/deep', getParentRoute: () => PostsRouteRoute, } as any) -const BlogBlogIdEditRoute = BlogBlogIdEditRouteImport.update({ - id: '/blog_/$blogId_/edit', - path: '/blog/$blogId/edit', - getParentRoute: () => rootRouteImport, -} as any) -const BlogBlogIdSlugRouteRoute = BlogBlogIdSlugRouteRouteImport.update({ - id: '/$slug', - path: '/$slug', - getParentRoute: () => BlogBlogIdRouteRoute, -} as any) const BlogBlogIdSlugBarRoute = BlogBlogIdSlugBarRouteImport.update({ id: '/$slug_/bar', path: '/$slug/bar', @@ -210,6 +210,13 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { + '/': { + id: '/' + path: '/' + fullPath: '/' + preLoaderRoute: typeof IndexRouteImport + parentRoute: typeof rootRouteImport + } '/_pathlessLayout': { id: '/_pathlessLayout' path: '' @@ -217,13 +224,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof PathlessLayoutRouteImport parentRoute: typeof rootRouteImport } - '/posts': { - id: '/posts' - path: '/posts' - fullPath: '/posts' - preLoaderRoute: typeof PostsRouteRouteImport - parentRoute: typeof rootRouteImport - } '/blog': { id: '/blog' path: '/blog' @@ -231,19 +231,19 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof BlogRouteRouteImport parentRoute: typeof rootRouteImport } - '/': { - id: '/' - path: '/' - fullPath: '/' - preLoaderRoute: typeof IndexRouteImport + '/posts': { + id: '/posts' + path: '/posts' + fullPath: '/posts' + preLoaderRoute: typeof PostsRouteRouteImport parentRoute: typeof rootRouteImport } - '/posts/': { - id: '/posts/' - path: '/' - fullPath: '/posts/' - preLoaderRoute: typeof PostsIndexRouteImport - parentRoute: typeof PostsRouteRoute + '/_pathlessLayout/settings': { + id: '/_pathlessLayout/settings' + path: '/settings' + fullPath: '/settings' + preLoaderRoute: typeof PathlessLayoutSettingsRouteImport + parentRoute: typeof PathlessLayoutRoute } '/blog/': { id: '/blog/' @@ -252,13 +252,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof BlogIndexRouteImport parentRoute: typeof BlogRouteRoute } - '/blog_/stats': { - id: '/blog_/stats' - path: '/blog/stats' - fullPath: '/blog/stats' - preLoaderRoute: typeof BlogStatsRouteImport - parentRoute: typeof rootRouteImport - } '/blog/$slug': { id: '/blog/$slug' path: '/$slug' @@ -266,13 +259,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof BlogSlugRouteImport parentRoute: typeof BlogRouteRoute } - '/_pathlessLayout/settings': { - id: '/_pathlessLayout/settings' - path: '/settings' - fullPath: '/settings' - preLoaderRoute: typeof PathlessLayoutSettingsRouteImport - parentRoute: typeof PathlessLayoutRoute - } '/blog_/$blogId': { id: '/blog_/$blogId' path: '/blog/$blogId' @@ -280,6 +266,34 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof BlogBlogIdRouteRouteImport parentRoute: typeof rootRouteImport } + '/blog_/stats': { + id: '/blog_/stats' + path: '/blog/stats' + fullPath: '/blog/stats' + preLoaderRoute: typeof BlogStatsRouteImport + parentRoute: typeof rootRouteImport + } + '/posts/': { + id: '/posts/' + path: '/' + fullPath: '/posts/' + preLoaderRoute: typeof PostsIndexRouteImport + parentRoute: typeof PostsRouteRoute + } + '/blog_/$blogId/$slug': { + id: '/blog_/$blogId/$slug' + path: '/$slug' + fullPath: '/blog/$blogId/$slug' + preLoaderRoute: typeof BlogBlogIdSlugRouteRouteImport + parentRoute: typeof BlogBlogIdRouteRoute + } + '/blog_/$blogId_/edit': { + id: '/blog_/$blogId_/edit' + path: '/blog/$blogId/edit' + fullPath: '/blog/$blogId/edit' + preLoaderRoute: typeof BlogBlogIdEditRouteImport + parentRoute: typeof rootRouteImport + } '/posts/$postId/': { id: '/posts/$postId/' path: '/$postId' @@ -294,20 +308,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof PostsPostIdDeepRouteImport parentRoute: typeof PostsRouteRoute } - '/blog_/$blogId_/edit': { - id: '/blog_/$blogId_/edit' - path: '/blog/$blogId/edit' - fullPath: '/blog/$blogId/edit' - preLoaderRoute: typeof BlogBlogIdEditRouteImport - parentRoute: typeof rootRouteImport - } - '/blog_/$blogId/$slug': { - id: '/blog_/$blogId/$slug' - path: '/$slug' - fullPath: '/blog/$blogId/$slug' - preLoaderRoute: typeof BlogBlogIdSlugRouteRouteImport - parentRoute: typeof BlogBlogIdRouteRoute - } '/blog_/$blogId/$slug_/bar': { id: '/blog_/$blogId/$slug_/bar' path: '/$slug/bar' diff --git a/packages/router-generator/tests/generator/numbers-in-path/routeTree.snapshot.ts b/packages/router-generator/tests/generator/numbers-in-path/routeTree.snapshot.ts index 76af935401..826e1b8b4f 100644 --- a/packages/router-generator/tests/generator/numbers-in-path/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/numbers-in-path/routeTree.snapshot.ts @@ -9,15 +9,15 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as AboutRouteImport } from './routes/about' -import { Route as R03RouteImport } from './routes/03' import { Route as IndexRouteImport } from './routes/index' -import { Route as R02IndexRouteImport } from './routes/02.index' +import { Route as R03RouteImport } from './routes/03' +import { Route as AboutRouteImport } from './routes/about' import { Route as R01ExampleIndexRouteImport } from './routes/01-example/index' +import { Route as R02IndexRouteImport } from './routes/02.index' -const AboutRoute = AboutRouteImport.update({ - id: '/about', - path: '/about', +const IndexRoute = IndexRouteImport.update({ + id: '/', + path: '/', getParentRoute: () => rootRouteImport, } as any) const R03Route = R03RouteImport.update({ @@ -25,14 +25,9 @@ const R03Route = R03RouteImport.update({ path: '/03', getParentRoute: () => rootRouteImport, } as any) -const IndexRoute = IndexRouteImport.update({ - id: '/', - path: '/', - getParentRoute: () => rootRouteImport, -} as any) -const R02IndexRoute = R02IndexRouteImport.update({ - id: '/02/', - path: '/02/', +const AboutRoute = AboutRouteImport.update({ + id: '/about', + path: '/about', getParentRoute: () => rootRouteImport, } as any) const R01ExampleIndexRoute = R01ExampleIndexRouteImport.update({ @@ -40,6 +35,11 @@ const R01ExampleIndexRoute = R01ExampleIndexRouteImport.update({ path: '/01-example/', getParentRoute: () => rootRouteImport, } as any) +const R02IndexRoute = R02IndexRouteImport.update({ + id: '/02/', + path: '/02/', + getParentRoute: () => rootRouteImport, +} as any) export interface FileRoutesByFullPath { '/': typeof IndexRoute @@ -81,11 +81,11 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/about': { - id: '/about' - path: '/about' - fullPath: '/about' - preLoaderRoute: typeof AboutRouteImport + '/': { + id: '/' + path: '/' + fullPath: '/' + preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } '/03': { @@ -95,18 +95,11 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof R03RouteImport parentRoute: typeof rootRouteImport } - '/': { - id: '/' - path: '/' - fullPath: '/' - preLoaderRoute: typeof IndexRouteImport - parentRoute: typeof rootRouteImport - } - '/02/': { - id: '/02/' - path: '/02' - fullPath: '/02/' - preLoaderRoute: typeof R02IndexRouteImport + '/about': { + id: '/about' + path: '/about' + fullPath: '/about' + preLoaderRoute: typeof AboutRouteImport parentRoute: typeof rootRouteImport } '/01-example/': { @@ -116,6 +109,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof R01ExampleIndexRouteImport parentRoute: typeof rootRouteImport } + '/02/': { + id: '/02/' + path: '/02' + fullPath: '/02/' + preLoaderRoute: typeof R02IndexRouteImport + parentRoute: typeof rootRouteImport + } } } diff --git a/packages/router-generator/tests/generator/physical-pathless-layout-escaped-underscore/routeTree.snapshot.ts b/packages/router-generator/tests/generator/physical-pathless-layout-escaped-underscore/routeTree.snapshot.ts index 53a35bf149..7c7789143a 100644 --- a/packages/router-generator/tests/generator/physical-pathless-layout-escaped-underscore/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/physical-pathless-layout-escaped-underscore/routeTree.snapshot.ts @@ -10,23 +10,23 @@ import { Route as rootRouteImport } from './routes/__root' import { Route as Char91__rootIndexChar93IndexRouteImport } from './routes/[__root-index]/index' -import { Route as LayoutRouteImport } from './routes/_layout' -import { Route as FooRouteImport } from './routes/[_]foo' -import { Route as Char91__literalChar93RouteImport } from './routes/[__literal]' import { Route as _layoutRouteImport } from './routes/__layout' -import { Route as RootIndexIndexRouteImport } from './routes/[_]root-index/index' -import { Route as LayoutNestedRouteImport } from './routes/_layout/_nested' -import { Route as LayoutBarRouteImport } from './routes/_layout/[_]bar' -import { Route as Layout_nested2RouteImport } from './routes/_layout/__nested2' -import { Route as LayoutChar91__doubleChar93RouteImport } from './routes/_layout/[__double]' +import { Route as Char91__literalChar93RouteImport } from './routes/[__literal]' +import { Route as FooRouteImport } from './routes/[_]foo' +import { Route as LayoutRouteImport } from './routes/_layout' import { Route as _layoutQuxRouteImport } from './routes/__layout/[_]qux' -import { Route as LayoutNestedTrailingIndexRouteImport } from './routes/_layout/nested-trailing[_]/index' -import { Route as LayoutNestedIndexIndexRouteImport } from './routes/_layout/[_]nested-index/index' +import { Route as LayoutChar91__doubleChar93RouteImport } from './routes/_layout/[__double]' +import { Route as Layout_nested2RouteImport } from './routes/_layout/__nested2' +import { Route as LayoutBarRouteImport } from './routes/_layout/[_]bar' +import { Route as LayoutNestedRouteImport } from './routes/_layout/_nested' +import { Route as RootIndexIndexRouteImport } from './routes/[_]root-index/index' import { Route as LayoutChar91__doubleIndexChar93IndexRouteImport } from './routes/_layout/[__double-index]/index' -import { Route as LayoutNestedBazRouteImport } from './routes/_layout/_nested/[_]baz' -import { Route as LayoutNestedIndexIdRouteImport } from './routes/_layout/[_]nested-index/$id' -import { Route as Layout_nested2DeepRouteImport } from './routes/_layout/__nested2/[_]deep' import { Route as LayoutChar91__doubleIndexChar93IdRouteImport } from './routes/_layout/[__double-index]/$id' +import { Route as Layout_nested2DeepRouteImport } from './routes/_layout/__nested2/[_]deep' +import { Route as LayoutNestedIndexIndexRouteImport } from './routes/_layout/[_]nested-index/index' +import { Route as LayoutNestedIndexIdRouteImport } from './routes/_layout/[_]nested-index/$id' +import { Route as LayoutNestedBazRouteImport } from './routes/_layout/_nested/[_]baz' +import { Route as LayoutNestedTrailingIndexRouteImport } from './routes/_layout/nested-trailing[_]/index' import { Route as LayoutNestedDeepIndexIndexRouteImport } from './routes/_layout/_nested/[_]deep-index/index' const Char91__rootIndexChar93IndexRoute = @@ -35,13 +35,8 @@ const Char91__rootIndexChar93IndexRoute = path: '/__root-index/', getParentRoute: () => rootRouteImport, } as any) -const LayoutRoute = LayoutRouteImport.update({ - id: '/_layout', - getParentRoute: () => rootRouteImport, -} as any) -const FooRoute = FooRouteImport.update({ - id: '/_foo', - path: '/_foo', +const _layoutRoute = _layoutRouteImport.update({ + id: '/__layout', getParentRoute: () => rootRouteImport, } as any) const Char91__literalChar93Route = Char91__literalChar93RouteImport.update({ @@ -49,17 +44,28 @@ const Char91__literalChar93Route = Char91__literalChar93RouteImport.update({ path: '/__literal', getParentRoute: () => rootRouteImport, } as any) -const _layoutRoute = _layoutRouteImport.update({ - id: '/__layout', +const FooRoute = FooRouteImport.update({ + id: '/_foo', + path: '/_foo', getParentRoute: () => rootRouteImport, } as any) -const RootIndexIndexRoute = RootIndexIndexRouteImport.update({ - id: '/_root-index/', - path: '/_root-index/', +const LayoutRoute = LayoutRouteImport.update({ + id: '/_layout', getParentRoute: () => rootRouteImport, } as any) -const LayoutNestedRoute = LayoutNestedRouteImport.update({ - id: '/_nested', +const _layoutQuxRoute = _layoutQuxRouteImport.update({ + id: '/_qux', + path: '/_qux', + getParentRoute: () => _layoutRoute, +} as any) +const LayoutChar91__doubleChar93Route = + LayoutChar91__doubleChar93RouteImport.update({ + id: '/__double', + path: '/__double', + getParentRoute: () => LayoutRoute, + } as any) +const Layout_nested2Route = Layout_nested2RouteImport.update({ + id: '/__nested2', getParentRoute: () => LayoutRoute, } as any) const LayoutBarRoute = LayoutBarRouteImport.update({ @@ -67,57 +73,51 @@ const LayoutBarRoute = LayoutBarRouteImport.update({ path: '/_bar', getParentRoute: () => LayoutRoute, } as any) -const Layout_nested2Route = Layout_nested2RouteImport.update({ - id: '/__nested2', +const LayoutNestedRoute = LayoutNestedRouteImport.update({ + id: '/_nested', getParentRoute: () => LayoutRoute, } as any) -const LayoutChar91__doubleChar93Route = - LayoutChar91__doubleChar93RouteImport.update({ - id: '/__double', - path: '/__double', +const RootIndexIndexRoute = RootIndexIndexRouteImport.update({ + id: '/_root-index/', + path: '/_root-index/', + getParentRoute: () => rootRouteImport, +} as any) +const LayoutChar91__doubleIndexChar93IndexRoute = + LayoutChar91__doubleIndexChar93IndexRouteImport.update({ + id: '/__double-index/', + path: '/__double-index/', getParentRoute: () => LayoutRoute, } as any) -const _layoutQuxRoute = _layoutQuxRouteImport.update({ - id: '/_qux', - path: '/_qux', - getParentRoute: () => _layoutRoute, -} as any) -const LayoutNestedTrailingIndexRoute = - LayoutNestedTrailingIndexRouteImport.update({ - id: '/nested-trailing_/', - path: '/nested-trailing_/', +const LayoutChar91__doubleIndexChar93IdRoute = + LayoutChar91__doubleIndexChar93IdRouteImport.update({ + id: '/__double-index/$id', + path: '/__double-index/$id', getParentRoute: () => LayoutRoute, } as any) +const Layout_nested2DeepRoute = Layout_nested2DeepRouteImport.update({ + id: '/_deep', + path: '/_deep', + getParentRoute: () => Layout_nested2Route, +} as any) const LayoutNestedIndexIndexRoute = LayoutNestedIndexIndexRouteImport.update({ id: '/_nested-index/', path: '/_nested-index/', getParentRoute: () => LayoutRoute, } as any) -const LayoutChar91__doubleIndexChar93IndexRoute = - LayoutChar91__doubleIndexChar93IndexRouteImport.update({ - id: '/__double-index/', - path: '/__double-index/', - getParentRoute: () => LayoutRoute, - } as any) -const LayoutNestedBazRoute = LayoutNestedBazRouteImport.update({ - id: '/_baz', - path: '/_baz', - getParentRoute: () => LayoutNestedRoute, -} as any) const LayoutNestedIndexIdRoute = LayoutNestedIndexIdRouteImport.update({ id: '/_nested-index/$id', path: '/_nested-index/$id', getParentRoute: () => LayoutRoute, } as any) -const Layout_nested2DeepRoute = Layout_nested2DeepRouteImport.update({ - id: '/_deep', - path: '/_deep', - getParentRoute: () => Layout_nested2Route, +const LayoutNestedBazRoute = LayoutNestedBazRouteImport.update({ + id: '/_baz', + path: '/_baz', + getParentRoute: () => LayoutNestedRoute, } as any) -const LayoutChar91__doubleIndexChar93IdRoute = - LayoutChar91__doubleIndexChar93IdRouteImport.update({ - id: '/__double-index/$id', - path: '/__double-index/$id', +const LayoutNestedTrailingIndexRoute = + LayoutNestedTrailingIndexRouteImport.update({ + id: '/nested-trailing_/', + path: '/nested-trailing_/', getParentRoute: () => LayoutRoute, } as any) const LayoutNestedDeepIndexIndexRoute = @@ -263,18 +263,11 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof Char91__rootIndexChar93IndexRouteImport parentRoute: typeof rootRouteImport } - '/_layout': { - id: '/_layout' + '/__layout': { + id: '/__layout' path: '' fullPath: '/' - preLoaderRoute: typeof LayoutRouteImport - parentRoute: typeof rootRouteImport - } - '/_foo': { - id: '/_foo' - path: '/_foo' - fullPath: '/_foo' - preLoaderRoute: typeof FooRouteImport + preLoaderRoute: typeof _layoutRouteImport parentRoute: typeof rootRouteImport } '/__literal': { @@ -284,25 +277,39 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof Char91__literalChar93RouteImport parentRoute: typeof rootRouteImport } - '/__layout': { - id: '/__layout' + '/_foo': { + id: '/_foo' + path: '/_foo' + fullPath: '/_foo' + preLoaderRoute: typeof FooRouteImport + parentRoute: typeof rootRouteImport + } + '/_layout': { + id: '/_layout' path: '' fullPath: '/' - preLoaderRoute: typeof _layoutRouteImport + preLoaderRoute: typeof LayoutRouteImport parentRoute: typeof rootRouteImport } - '/_root-index/': { - id: '/_root-index/' - path: '/_root-index' - fullPath: '/_root-index/' - preLoaderRoute: typeof RootIndexIndexRouteImport - parentRoute: typeof rootRouteImport + '/__layout/_qux': { + id: '/__layout/_qux' + path: '/_qux' + fullPath: '/_qux' + preLoaderRoute: typeof _layoutQuxRouteImport + parentRoute: typeof _layoutRoute } - '/_layout/_nested': { - id: '/_layout/_nested' + '/_layout/__double': { + id: '/_layout/__double' + path: '/__double' + fullPath: '/__double' + preLoaderRoute: typeof LayoutChar91__doubleChar93RouteImport + parentRoute: typeof LayoutRoute + } + '/_layout/__nested2': { + id: '/_layout/__nested2' path: '' fullPath: '/' - preLoaderRoute: typeof LayoutNestedRouteImport + preLoaderRoute: typeof Layout_nested2RouteImport parentRoute: typeof LayoutRoute } '/_layout/_bar': { @@ -312,34 +319,41 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof LayoutBarRouteImport parentRoute: typeof LayoutRoute } - '/_layout/__nested2': { - id: '/_layout/__nested2' + '/_layout/_nested': { + id: '/_layout/_nested' path: '' fullPath: '/' - preLoaderRoute: typeof Layout_nested2RouteImport + preLoaderRoute: typeof LayoutNestedRouteImport parentRoute: typeof LayoutRoute } - '/_layout/__double': { - id: '/_layout/__double' - path: '/__double' - fullPath: '/__double' - preLoaderRoute: typeof LayoutChar91__doubleChar93RouteImport - parentRoute: typeof LayoutRoute + '/_root-index/': { + id: '/_root-index/' + path: '/_root-index' + fullPath: '/_root-index/' + preLoaderRoute: typeof RootIndexIndexRouteImport + parentRoute: typeof rootRouteImport } - '/__layout/_qux': { - id: '/__layout/_qux' - path: '/_qux' - fullPath: '/_qux' - preLoaderRoute: typeof _layoutQuxRouteImport - parentRoute: typeof _layoutRoute + '/_layout/__double-index/': { + id: '/_layout/__double-index/' + path: '/__double-index' + fullPath: '/__double-index/' + preLoaderRoute: typeof LayoutChar91__doubleIndexChar93IndexRouteImport + parentRoute: typeof LayoutRoute } - '/_layout/nested-trailing_/': { - id: '/_layout/nested-trailing_/' - path: '/nested-trailing_' - fullPath: '/nested-trailing_/' - preLoaderRoute: typeof LayoutNestedTrailingIndexRouteImport + '/_layout/__double-index/$id': { + id: '/_layout/__double-index/$id' + path: '/__double-index/$id' + fullPath: '/__double-index/$id' + preLoaderRoute: typeof LayoutChar91__doubleIndexChar93IdRouteImport parentRoute: typeof LayoutRoute } + '/_layout/__nested2/_deep': { + id: '/_layout/__nested2/_deep' + path: '/_deep' + fullPath: '/_deep' + preLoaderRoute: typeof Layout_nested2DeepRouteImport + parentRoute: typeof Layout_nested2Route + } '/_layout/_nested-index/': { id: '/_layout/_nested-index/' path: '/_nested-index' @@ -347,11 +361,11 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof LayoutNestedIndexIndexRouteImport parentRoute: typeof LayoutRoute } - '/_layout/__double-index/': { - id: '/_layout/__double-index/' - path: '/__double-index' - fullPath: '/__double-index/' - preLoaderRoute: typeof LayoutChar91__doubleIndexChar93IndexRouteImport + '/_layout/_nested-index/$id': { + id: '/_layout/_nested-index/$id' + path: '/_nested-index/$id' + fullPath: '/_nested-index/$id' + preLoaderRoute: typeof LayoutNestedIndexIdRouteImport parentRoute: typeof LayoutRoute } '/_layout/_nested/_baz': { @@ -361,25 +375,11 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof LayoutNestedBazRouteImport parentRoute: typeof LayoutNestedRoute } - '/_layout/_nested-index/$id': { - id: '/_layout/_nested-index/$id' - path: '/_nested-index/$id' - fullPath: '/_nested-index/$id' - preLoaderRoute: typeof LayoutNestedIndexIdRouteImport - parentRoute: typeof LayoutRoute - } - '/_layout/__nested2/_deep': { - id: '/_layout/__nested2/_deep' - path: '/_deep' - fullPath: '/_deep' - preLoaderRoute: typeof Layout_nested2DeepRouteImport - parentRoute: typeof Layout_nested2Route - } - '/_layout/__double-index/$id': { - id: '/_layout/__double-index/$id' - path: '/__double-index/$id' - fullPath: '/__double-index/$id' - preLoaderRoute: typeof LayoutChar91__doubleIndexChar93IdRouteImport + '/_layout/nested-trailing_/': { + id: '/_layout/nested-trailing_/' + path: '/nested-trailing_' + fullPath: '/nested-trailing_/' + preLoaderRoute: typeof LayoutNestedTrailingIndexRouteImport parentRoute: typeof LayoutRoute } '/_layout/_nested/_deep-index/': { diff --git a/packages/router-generator/tests/generator/prefix-suffix/routeTree.snapshot.ts b/packages/router-generator/tests/generator/prefix-suffix/routeTree.snapshot.ts index 5f7f854d9f..2ef38f491d 100644 --- a/packages/router-generator/tests/generator/prefix-suffix/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/prefix-suffix/routeTree.snapshot.ts @@ -9,15 +9,20 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as WildcardChar123Char125suffixRouteImport } from './routes/wildcard/{$}suffix' -import { Route as WildcardChar123Char125DotsuffixRouteImport } from './routes/wildcard/{$}[.]suffix' -import { Route as WildcardPrefixChar123Char125RouteImport } from './routes/wildcard/prefix{$}' import { Route as WildcardSplatRouteImport } from './routes/wildcard/$' +import { Route as WildcardPrefixChar123Char125RouteImport } from './routes/wildcard/prefix{$}' +import { Route as WildcardChar123Char125DotsuffixRouteImport } from './routes/wildcard/{$}[.]suffix' +import { Route as WildcardChar123Char125suffixRouteImport } from './routes/wildcard/{$}suffix' -const WildcardChar123Char125suffixRoute = - WildcardChar123Char125suffixRouteImport.update({ - id: '/wildcard/{$}suffix', - path: '/wildcard/{$}suffix', +const WildcardSplatRoute = WildcardSplatRouteImport.update({ + id: '/wildcard/$', + path: '/wildcard/$', + getParentRoute: () => rootRouteImport, +} as any) +const WildcardPrefixChar123Char125Route = + WildcardPrefixChar123Char125RouteImport.update({ + id: '/wildcard/prefix{$}', + path: '/wildcard/prefix{$}', getParentRoute: () => rootRouteImport, } as any) const WildcardChar123Char125DotsuffixRoute = @@ -26,17 +31,12 @@ const WildcardChar123Char125DotsuffixRoute = path: '/wildcard/{$}.suffix', getParentRoute: () => rootRouteImport, } as any) -const WildcardPrefixChar123Char125Route = - WildcardPrefixChar123Char125RouteImport.update({ - id: '/wildcard/prefix{$}', - path: '/wildcard/prefix{$}', +const WildcardChar123Char125suffixRoute = + WildcardChar123Char125suffixRouteImport.update({ + id: '/wildcard/{$}suffix', + path: '/wildcard/{$}suffix', getParentRoute: () => rootRouteImport, } as any) -const WildcardSplatRoute = WildcardSplatRouteImport.update({ - id: '/wildcard/$', - path: '/wildcard/$', - getParentRoute: () => rootRouteImport, -} as any) export interface FileRoutesByFullPath { '/wildcard/$': typeof WildcardSplatRoute @@ -87,18 +87,11 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/wildcard/{$}suffix': { - id: '/wildcard/{$}suffix' - path: '/wildcard/{$}suffix' - fullPath: '/wildcard/{$}suffix' - preLoaderRoute: typeof WildcardChar123Char125suffixRouteImport - parentRoute: typeof rootRouteImport - } - '/wildcard/{$}.suffix': { - id: '/wildcard/{$}.suffix' - path: '/wildcard/{$}.suffix' - fullPath: '/wildcard/{$}.suffix' - preLoaderRoute: typeof WildcardChar123Char125DotsuffixRouteImport + '/wildcard/$': { + id: '/wildcard/$' + path: '/wildcard/$' + fullPath: '/wildcard/$' + preLoaderRoute: typeof WildcardSplatRouteImport parentRoute: typeof rootRouteImport } '/wildcard/prefix{$}': { @@ -108,11 +101,18 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof WildcardPrefixChar123Char125RouteImport parentRoute: typeof rootRouteImport } - '/wildcard/$': { - id: '/wildcard/$' - path: '/wildcard/$' - fullPath: '/wildcard/$' - preLoaderRoute: typeof WildcardSplatRouteImport + '/wildcard/{$}.suffix': { + id: '/wildcard/{$}.suffix' + path: '/wildcard/{$}.suffix' + fullPath: '/wildcard/{$}.suffix' + preLoaderRoute: typeof WildcardChar123Char125DotsuffixRouteImport + parentRoute: typeof rootRouteImport + } + '/wildcard/{$}suffix': { + id: '/wildcard/{$}suffix' + path: '/wildcard/{$}suffix' + fullPath: '/wildcard/{$}suffix' + preLoaderRoute: typeof WildcardChar123Char125suffixRouteImport parentRoute: typeof rootRouteImport } } diff --git a/packages/router-generator/tests/generator/regex-tokens-inline/routeTree.snapshot.ts b/packages/router-generator/tests/generator/regex-tokens-inline/routeTree.snapshot.ts index 3909bbe9f4..669cebaf59 100644 --- a/packages/router-generator/tests/generator/regex-tokens-inline/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/regex-tokens-inline/routeTree.snapshot.ts @@ -9,21 +9,21 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as DashboardMainLayoutRouteImport } from './routes/dashboard.main-layout' import { Route as IndexPageRouteImport } from './routes/index-page' +import { Route as DashboardMainLayoutRouteImport } from './routes/dashboard.main-layout' import { Route as DashboardHomePageRouteImport } from './routes/dashboard.home-page' import { Route as DashboardSettingsRouteImport } from './routes/dashboard.settings' -const DashboardMainLayoutRoute = DashboardMainLayoutRouteImport.update({ - id: '/dashboard', - path: '/dashboard', - getParentRoute: () => rootRouteImport, -} as any) const IndexPageRoute = IndexPageRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) +const DashboardMainLayoutRoute = DashboardMainLayoutRouteImport.update({ + id: '/dashboard', + path: '/dashboard', + getParentRoute: () => rootRouteImport, +} as any) const DashboardHomePageRoute = DashboardHomePageRouteImport.update({ id: '/', path: '/', @@ -68,13 +68,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/dashboard': { - id: '/dashboard' - path: '/dashboard' - fullPath: '/dashboard' - preLoaderRoute: typeof DashboardMainLayoutRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -82,6 +75,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof IndexPageRouteImport parentRoute: typeof rootRouteImport } + '/dashboard': { + id: '/dashboard' + path: '/dashboard' + fullPath: '/dashboard' + preLoaderRoute: typeof DashboardMainLayoutRouteImport + parentRoute: typeof rootRouteImport + } '/dashboard/': { id: '/dashboard/' path: '/' diff --git a/packages/router-generator/tests/generator/regex-tokens-json/routeTree.snapshot.ts b/packages/router-generator/tests/generator/regex-tokens-json/routeTree.snapshot.ts index 3909bbe9f4..669cebaf59 100644 --- a/packages/router-generator/tests/generator/regex-tokens-json/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/regex-tokens-json/routeTree.snapshot.ts @@ -9,21 +9,21 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as DashboardMainLayoutRouteImport } from './routes/dashboard.main-layout' import { Route as IndexPageRouteImport } from './routes/index-page' +import { Route as DashboardMainLayoutRouteImport } from './routes/dashboard.main-layout' import { Route as DashboardHomePageRouteImport } from './routes/dashboard.home-page' import { Route as DashboardSettingsRouteImport } from './routes/dashboard.settings' -const DashboardMainLayoutRoute = DashboardMainLayoutRouteImport.update({ - id: '/dashboard', - path: '/dashboard', - getParentRoute: () => rootRouteImport, -} as any) const IndexPageRoute = IndexPageRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) +const DashboardMainLayoutRoute = DashboardMainLayoutRouteImport.update({ + id: '/dashboard', + path: '/dashboard', + getParentRoute: () => rootRouteImport, +} as any) const DashboardHomePageRoute = DashboardHomePageRouteImport.update({ id: '/', path: '/', @@ -68,13 +68,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/dashboard': { - id: '/dashboard' - path: '/dashboard' - fullPath: '/dashboard' - preLoaderRoute: typeof DashboardMainLayoutRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -82,6 +75,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof IndexPageRouteImport parentRoute: typeof rootRouteImport } + '/dashboard': { + id: '/dashboard' + path: '/dashboard' + fullPath: '/dashboard' + preLoaderRoute: typeof DashboardMainLayoutRouteImport + parentRoute: typeof rootRouteImport + } '/dashboard/': { id: '/dashboard/' path: '/' diff --git a/packages/router-generator/tests/generator/regex-tokens-plus-json/routeTree.snapshot.ts b/packages/router-generator/tests/generator/regex-tokens-plus-json/routeTree.snapshot.ts index b9b7117716..74c38f90ad 100644 --- a/packages/router-generator/tests/generator/regex-tokens-plus-json/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/regex-tokens-plus-json/routeTree.snapshot.ts @@ -9,21 +9,21 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as DashboardChar43layoutRouteImport } from './routes/dashboard/+layout' import { Route as Char43pageRouteImport } from './routes/+page' +import { Route as DashboardChar43layoutRouteImport } from './routes/dashboard/+layout' import { Route as DashboardChar43pageRouteImport } from './routes/dashboard/+page' import { Route as DashboardSettingsRouteImport } from './routes/dashboard/settings' -const DashboardChar43layoutRoute = DashboardChar43layoutRouteImport.update({ - id: '/dashboard', - path: '/dashboard', - getParentRoute: () => rootRouteImport, -} as any) const Char43pageRoute = Char43pageRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) +const DashboardChar43layoutRoute = DashboardChar43layoutRouteImport.update({ + id: '/dashboard', + path: '/dashboard', + getParentRoute: () => rootRouteImport, +} as any) const DashboardChar43pageRoute = DashboardChar43pageRouteImport.update({ id: '/', path: '/', @@ -68,13 +68,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/dashboard': { - id: '/dashboard' - path: '/dashboard' - fullPath: '/dashboard' - preLoaderRoute: typeof DashboardChar43layoutRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -82,6 +75,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof Char43pageRouteImport parentRoute: typeof rootRouteImport } + '/dashboard': { + id: '/dashboard' + path: '/dashboard' + fullPath: '/dashboard' + preLoaderRoute: typeof DashboardChar43layoutRouteImport + parentRoute: typeof rootRouteImport + } '/dashboard/': { id: '/dashboard/' path: '/' diff --git a/packages/router-generator/tests/generator/root-export-specifier/routeTree.snapshot.ts b/packages/router-generator/tests/generator/root-export-specifier/routeTree.snapshot.ts index 59499d9fbf..12bc916ae4 100644 --- a/packages/router-generator/tests/generator/root-export-specifier/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/root-export-specifier/routeTree.snapshot.ts @@ -9,19 +9,19 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as AboutRouteImport } from './routes/about' import { Route as IndexRouteImport } from './routes/index' +import { Route as AboutRouteImport } from './routes/about' -const AboutRoute = AboutRouteImport.update({ - id: '/about', - path: '/about', - getParentRoute: () => rootRouteImport, -} as any) const IndexRoute = IndexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) +const AboutRoute = AboutRouteImport.update({ + id: '/about', + path: '/about', + getParentRoute: () => rootRouteImport, +} as any) export interface FileRoutesByFullPath { '/': typeof IndexRoute @@ -51,13 +51,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/about': { - id: '/about' - path: '/about' - fullPath: '/about' - preLoaderRoute: typeof AboutRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -65,6 +58,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } + '/about': { + id: '/about' + path: '/about' + fullPath: '/about' + preLoaderRoute: typeof AboutRouteImport + parentRoute: typeof rootRouteImport + } } } diff --git a/packages/router-generator/tests/generator/route-groups/routeTree.snapshot.ts b/packages/router-generator/tests/generator/route-groups/routeTree.snapshot.ts index f2e84bbbb7..e76c675d2c 100644 --- a/packages/router-generator/tests/generator/route-groups/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/route-groups/routeTree.snapshot.ts @@ -12,13 +12,13 @@ import { createFileRoute } from '@tanstack/react-router' import { Route as rootRouteImport } from './routes/__root' import { Route as barBarRouteImport } from './routes/(bar)/_bar' -import { Route as fooAsdfLayoutRouteImport } from './routes/(foo)/asdf/_layout' import { Route as barBarHelloRouteImport } from './routes/(bar)/_bar.hello' -import { Route as fooAsdfLayoutFooRouteImport } from './routes/(foo)/asdf/_layout.foo' -import { Route as fooAsdfbarIdRouteImport } from './routes/(foo)/asdf/(bar)/$id' +import { Route as fooAsdfLayoutRouteImport } from './routes/(foo)/asdf/_layout' import { Route as fooAsdfanotherGroupLayoutRouteImport } from './routes/(foo)/asdf/(another-group)/_layout' -import { Route as fooAsdfbarLayoutAboutRouteImport } from './routes/(foo)/asdf/(bar)/_layout.about' +import { Route as fooAsdfbarIdRouteImport } from './routes/(foo)/asdf/(bar)/$id' +import { Route as fooAsdfLayoutFooRouteImport } from './routes/(foo)/asdf/_layout.foo' import { Route as fooAsdfanotherGroupLayoutBazRouteImport } from './routes/(foo)/asdf/(another-group)/_layout.baz' +import { Route as fooAsdfbarLayoutAboutRouteImport } from './routes/(foo)/asdf/(bar)/_layout.about' const fooAsdfbarLayoutXyzLazyRouteImport = createFileRoute( '/(foo)/asdf/(bar)/_layout/xyz', @@ -28,24 +28,14 @@ const barBarRoute = barBarRouteImport.update({ id: '/(bar)/_bar', getParentRoute: () => rootRouteImport, } as any) -const fooAsdfLayoutRoute = fooAsdfLayoutRouteImport.update({ - id: '/(foo)/asdf/_layout', - path: '/asdf', - getParentRoute: () => rootRouteImport, -} as any) const barBarHelloRoute = barBarHelloRouteImport.update({ id: '/hello', path: '/hello', getParentRoute: () => barBarRoute, } as any) -const fooAsdfLayoutFooRoute = fooAsdfLayoutFooRouteImport.update({ - id: '/foo', - path: '/foo', - getParentRoute: () => fooAsdfLayoutRoute, -} as any) -const fooAsdfbarIdRoute = fooAsdfbarIdRouteImport.update({ - id: '/(foo)/asdf/(bar)/$id', - path: '/asdf/$id', +const fooAsdfLayoutRoute = fooAsdfLayoutRouteImport.update({ + id: '/(foo)/asdf/_layout', + path: '/asdf', getParentRoute: () => rootRouteImport, } as any) const fooAsdfanotherGroupLayoutRoute = @@ -54,6 +44,27 @@ const fooAsdfanotherGroupLayoutRoute = path: '/asdf', getParentRoute: () => rootRouteImport, } as any) +const fooAsdfbarIdRoute = fooAsdfbarIdRouteImport.update({ + id: '/(foo)/asdf/(bar)/$id', + path: '/asdf/$id', + getParentRoute: () => rootRouteImport, +} as any) +const fooAsdfLayoutFooRoute = fooAsdfLayoutFooRouteImport.update({ + id: '/foo', + path: '/foo', + getParentRoute: () => fooAsdfLayoutRoute, +} as any) +const fooAsdfanotherGroupLayoutBazRoute = + fooAsdfanotherGroupLayoutBazRouteImport.update({ + id: '/baz', + path: '/baz', + getParentRoute: () => fooAsdfanotherGroupLayoutRoute, + } as any) +const fooAsdfbarLayoutAboutRoute = fooAsdfbarLayoutAboutRouteImport.update({ + id: '/(foo)/asdf/(bar)/_layout/about', + path: '/asdf/about', + getParentRoute: () => rootRouteImport, +} as any) const fooAsdfbarLayoutXyzLazyRoute = fooAsdfbarLayoutXyzLazyRouteImport .update({ id: '/(foo)/asdf/(bar)/_layout/xyz', @@ -63,17 +74,6 @@ const fooAsdfbarLayoutXyzLazyRoute = fooAsdfbarLayoutXyzLazyRouteImport .lazy(() => import('./routes/(foo)/asdf/(bar)/_layout.xyz.lazy').then((d) => d.Route), ) -const fooAsdfbarLayoutAboutRoute = fooAsdfbarLayoutAboutRouteImport.update({ - id: '/(foo)/asdf/(bar)/_layout/about', - path: '/asdf/about', - getParentRoute: () => rootRouteImport, -} as any) -const fooAsdfanotherGroupLayoutBazRoute = - fooAsdfanotherGroupLayoutBazRouteImport.update({ - id: '/baz', - path: '/baz', - getParentRoute: () => fooAsdfanotherGroupLayoutRoute, - } as any) export interface FileRoutesByFullPath { '/hello': typeof barBarHelloRoute @@ -155,13 +155,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof barBarRouteImport parentRoute: typeof rootRouteImport } - '/(foo)/asdf/_layout': { - id: '/(foo)/asdf/_layout' - path: '/asdf' - fullPath: '/asdf' - preLoaderRoute: typeof fooAsdfLayoutRouteImport - parentRoute: typeof rootRouteImport - } '/(bar)/_bar/hello': { id: '/(bar)/_bar/hello' path: '/hello' @@ -169,18 +162,11 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof barBarHelloRouteImport parentRoute: typeof barBarRoute } - '/(foo)/asdf/_layout/foo': { - id: '/(foo)/asdf/_layout/foo' - path: '/foo' - fullPath: '/asdf/foo' - preLoaderRoute: typeof fooAsdfLayoutFooRouteImport - parentRoute: typeof fooAsdfLayoutRoute - } - '/(foo)/asdf/(bar)/$id': { - id: '/(foo)/asdf/(bar)/$id' - path: '/asdf/$id' - fullPath: '/asdf/$id' - preLoaderRoute: typeof fooAsdfbarIdRouteImport + '/(foo)/asdf/_layout': { + id: '/(foo)/asdf/_layout' + path: '/asdf' + fullPath: '/asdf' + preLoaderRoute: typeof fooAsdfLayoutRouteImport parentRoute: typeof rootRouteImport } '/(foo)/asdf/(another-group)/_layout': { @@ -190,19 +176,19 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof fooAsdfanotherGroupLayoutRouteImport parentRoute: typeof rootRouteImport } - '/(foo)/asdf/(bar)/_layout/xyz': { - id: '/(foo)/asdf/(bar)/_layout/xyz' - path: '/asdf/xyz' - fullPath: '/asdf/xyz' - preLoaderRoute: typeof fooAsdfbarLayoutXyzLazyRouteImport + '/(foo)/asdf/(bar)/$id': { + id: '/(foo)/asdf/(bar)/$id' + path: '/asdf/$id' + fullPath: '/asdf/$id' + preLoaderRoute: typeof fooAsdfbarIdRouteImport parentRoute: typeof rootRouteImport } - '/(foo)/asdf/(bar)/_layout/about': { - id: '/(foo)/asdf/(bar)/_layout/about' - path: '/asdf/about' - fullPath: '/asdf/about' - preLoaderRoute: typeof fooAsdfbarLayoutAboutRouteImport - parentRoute: typeof rootRouteImport + '/(foo)/asdf/_layout/foo': { + id: '/(foo)/asdf/_layout/foo' + path: '/foo' + fullPath: '/asdf/foo' + preLoaderRoute: typeof fooAsdfLayoutFooRouteImport + parentRoute: typeof fooAsdfLayoutRoute } '/(foo)/asdf/(another-group)/_layout/baz': { id: '/(foo)/asdf/(another-group)/_layout/baz' @@ -211,6 +197,20 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof fooAsdfanotherGroupLayoutBazRouteImport parentRoute: typeof fooAsdfanotherGroupLayoutRoute } + '/(foo)/asdf/(bar)/_layout/about': { + id: '/(foo)/asdf/(bar)/_layout/about' + path: '/asdf/about' + fullPath: '/asdf/about' + preLoaderRoute: typeof fooAsdfbarLayoutAboutRouteImport + parentRoute: typeof rootRouteImport + } + '/(foo)/asdf/(bar)/_layout/xyz': { + id: '/(foo)/asdf/(bar)/_layout/xyz' + path: '/asdf/xyz' + fullPath: '/asdf/xyz' + preLoaderRoute: typeof fooAsdfbarLayoutXyzLazyRouteImport + parentRoute: typeof rootRouteImport + } } } diff --git a/packages/router-generator/tests/generator/routeFileIgnore/routeTree.snapshot.ts b/packages/router-generator/tests/generator/routeFileIgnore/routeTree.snapshot.ts index 33a4093b9e..ceb6811cf7 100644 --- a/packages/router-generator/tests/generator/routeFileIgnore/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/routeFileIgnore/routeTree.snapshot.ts @@ -9,19 +9,19 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as BlogRouteRouteImport } from './routes/blog.route' import { Route as IndexRouteImport } from './routes/index' +import { Route as BlogRouteRouteImport } from './routes/blog.route' -const BlogRouteRoute = BlogRouteRouteImport.update({ - id: '/blog', - path: '/blog', - getParentRoute: () => rootRouteImport, -} as any) const IndexRoute = IndexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) +const BlogRouteRoute = BlogRouteRouteImport.update({ + id: '/blog', + path: '/blog', + getParentRoute: () => rootRouteImport, +} as any) export interface FileRoutesByFullPath { '/': typeof IndexRoute @@ -51,13 +51,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/blog': { - id: '/blog' - path: '/blog' - fullPath: '/blog' - preLoaderRoute: typeof BlogRouteRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -65,6 +58,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } + '/blog': { + id: '/blog' + path: '/blog' + fullPath: '/blog' + preLoaderRoute: typeof BlogRouteRouteImport + parentRoute: typeof rootRouteImport + } } } diff --git a/packages/router-generator/tests/generator/routeFilePrefix/routeTree.snapshot.ts b/packages/router-generator/tests/generator/routeFilePrefix/routeTree.snapshot.ts index 46ee215c03..9805633c47 100644 --- a/packages/router-generator/tests/generator/routeFilePrefix/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/routeFilePrefix/routeTree.snapshot.ts @@ -9,19 +9,19 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/r&__root' -import { Route as BlogRouteRouteImport } from './routes/r&blog.route' import { Route as IndexRouteImport } from './routes/r&index' +import { Route as BlogRouteRouteImport } from './routes/r&blog.route' -const BlogRouteRoute = BlogRouteRouteImport.update({ - id: '/blog', - path: '/blog', - getParentRoute: () => rootRouteImport, -} as any) const IndexRoute = IndexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) +const BlogRouteRoute = BlogRouteRouteImport.update({ + id: '/blog', + path: '/blog', + getParentRoute: () => rootRouteImport, +} as any) export interface FileRoutesByFullPath { '/': typeof IndexRoute @@ -51,13 +51,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/blog': { - id: '/blog' - path: '/blog' - fullPath: '/blog' - preLoaderRoute: typeof BlogRouteRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -65,6 +58,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } + '/blog': { + id: '/blog' + path: '/blog' + fullPath: '/blog' + preLoaderRoute: typeof BlogRouteRouteImport + parentRoute: typeof rootRouteImport + } } } diff --git a/packages/router-generator/tests/generator/single-level/routeTree.snapshot.ts b/packages/router-generator/tests/generator/single-level/routeTree.snapshot.ts index b60f0b934f..12b48f052a 100644 --- a/packages/router-generator/tests/generator/single-level/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/single-level/routeTree.snapshot.ts @@ -9,19 +9,19 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as PostsRouteImport } from './routes/posts' import { Route as IndexRouteImport } from './routes/index' +import { Route as PostsRouteImport } from './routes/posts' -const PostsRoute = PostsRouteImport.update({ - id: '/posts', - path: '/posts', - getParentRoute: () => rootRouteImport, -} as any) const IndexRoute = IndexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) +const PostsRoute = PostsRouteImport.update({ + id: '/posts', + path: '/posts', + getParentRoute: () => rootRouteImport, +} as any) export interface FileRoutesByFullPath { '/': typeof IndexRoute @@ -51,13 +51,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/posts': { - id: '/posts' - path: '/posts' - fullPath: '/posts' - preLoaderRoute: typeof PostsRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -65,6 +58,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } + '/posts': { + id: '/posts' + path: '/posts' + fullPath: '/posts' + preLoaderRoute: typeof PostsRouteImport + parentRoute: typeof rootRouteImport + } } } diff --git a/packages/router-generator/tests/generator/types-disabled/routeTree.snapshot.js b/packages/router-generator/tests/generator/types-disabled/routeTree.snapshot.js index 9c410eea0f..4dc8f12ad7 100644 --- a/packages/router-generator/tests/generator/types-disabled/routeTree.snapshot.js +++ b/packages/router-generator/tests/generator/types-disabled/routeTree.snapshot.js @@ -9,24 +9,19 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as PostsRouteImport } from './routes/posts' import { Route as IndexRouteImport } from './routes/index' -import { Route as UsersUserIdRouteImport } from './routes/users.$userId' +import { Route as PostsRouteImport } from './routes/posts' import { Route as PostsPostIdRouteImport } from './routes/posts/$postId' +import { Route as UsersUserIdRouteImport } from './routes/users.$userId' -const PostsRoute = PostsRouteImport.update({ - id: '/posts', - path: '/posts', - getParentRoute: () => rootRouteImport, -}) const IndexRoute = IndexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, }) -const UsersUserIdRoute = UsersUserIdRouteImport.update({ - id: '/users/$userId', - path: '/users/$userId', +const PostsRoute = PostsRouteImport.update({ + id: '/posts', + path: '/posts', getParentRoute: () => rootRouteImport, }) const PostsPostIdRoute = PostsPostIdRouteImport.update({ @@ -34,6 +29,11 @@ const PostsPostIdRoute = PostsPostIdRouteImport.update({ path: '/$postId', getParentRoute: () => PostsRoute, }) +const UsersUserIdRoute = UsersUserIdRouteImport.update({ + id: '/users/$userId', + path: '/users/$userId', + getParentRoute: () => rootRouteImport, +}) const PostsRouteChildren = { PostsPostIdRoute: PostsPostIdRoute, diff --git a/packages/router-generator/tests/generator/virtual-config-file-default-export/routeTree.snapshot.ts b/packages/router-generator/tests/generator/virtual-config-file-default-export/routeTree.snapshot.ts index 3d3c2de9d5..6b16924d5b 100644 --- a/packages/router-generator/tests/generator/virtual-config-file-default-export/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/virtual-config-file-default-export/routeTree.snapshot.ts @@ -9,51 +9,61 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/root' -import { Route as layoutRouteImport } from './routes/layout' import { Route as indexRouteImport } from './routes/index' -import { Route as dbDashboardRouteImport } from './routes/db/dashboard' +import { Route as layoutRouteImport } from './routes/layout' import { Route as pagesRouteImport } from './routes/pages' -import { Route as HelloIndexRouteImport } from './routes/subtree/index' -import { Route as dbDashboardInvoicesRouteImport } from './routes/db/dashboard-invoices' +import { Route as dbDashboardRouteImport } from './routes/db/dashboard' import { Route as dbDashboardIndexRouteImport } from './routes/db/dashboard-index' +import { Route as dbDashboardInvoicesRouteImport } from './routes/db/dashboard-invoices' +import { Route as HelloIndexRouteImport } from './routes/subtree/index' +import { Route as dbInvoicesIndexRouteImport } from './routes/db/invoices-index' +import { Route as dbInvoiceDetailRouteImport } from './routes/db/invoice-detail' import { Route as HelloFooIndexRouteImport } from './routes/subtree/foo/index' import { Route as HelloFooIdRouteImport } from './routes/subtree/foo/$id' -import { Route as dbInvoiceDetailRouteImport } from './routes/db/invoice-detail' -import { Route as dbInvoicesIndexRouteImport } from './routes/db/invoices-index' -const layoutRoute = layoutRouteImport.update({ - id: '/_layout', - getParentRoute: () => rootRouteImport, -} as any) const indexRoute = indexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) -const dbDashboardRoute = dbDashboardRouteImport.update({ - id: '/dashboard', - path: '/dashboard', - getParentRoute: () => layoutRoute, +const layoutRoute = layoutRouteImport.update({ + id: '/_layout', + getParentRoute: () => rootRouteImport, } as any) const pagesRoute = pagesRouteImport.update({ id: '/$lang/', path: '/$lang/', getParentRoute: () => rootRouteImport, } as any) -const HelloIndexRoute = HelloIndexRouteImport.update({ - id: '/hello/', - path: '/hello/', +const dbDashboardRoute = dbDashboardRouteImport.update({ + id: '/dashboard', + path: '/dashboard', getParentRoute: () => layoutRoute, } as any) +const dbDashboardIndexRoute = dbDashboardIndexRouteImport.update({ + id: '/', + path: '/', + getParentRoute: () => dbDashboardRoute, +} as any) const dbDashboardInvoicesRoute = dbDashboardInvoicesRouteImport.update({ id: '/invoices', path: '/invoices', getParentRoute: () => dbDashboardRoute, } as any) -const dbDashboardIndexRoute = dbDashboardIndexRouteImport.update({ +const HelloIndexRoute = HelloIndexRouteImport.update({ + id: '/hello/', + path: '/hello/', + getParentRoute: () => layoutRoute, +} as any) +const dbInvoicesIndexRoute = dbInvoicesIndexRouteImport.update({ id: '/', path: '/', - getParentRoute: () => dbDashboardRoute, + getParentRoute: () => dbDashboardInvoicesRoute, +} as any) +const dbInvoiceDetailRoute = dbInvoiceDetailRouteImport.update({ + id: '/$id', + path: '/$id', + getParentRoute: () => dbDashboardInvoicesRoute, } as any) const HelloFooIndexRoute = HelloFooIndexRouteImport.update({ id: '/hello/foo/', @@ -65,16 +75,6 @@ const HelloFooIdRoute = HelloFooIdRouteImport.update({ path: '/hello/foo/$id', getParentRoute: () => layoutRoute, } as any) -const dbInvoiceDetailRoute = dbInvoiceDetailRouteImport.update({ - id: '/$id', - path: '/$id', - getParentRoute: () => dbDashboardInvoicesRoute, -} as any) -const dbInvoicesIndexRoute = dbInvoicesIndexRouteImport.update({ - id: '/', - path: '/', - getParentRoute: () => dbDashboardInvoicesRoute, -} as any) export interface FileRoutesByFullPath { '/': typeof indexRoute @@ -158,13 +158,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/_layout': { - id: '/_layout' - path: '' - fullPath: '/' - preLoaderRoute: typeof layoutRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -172,12 +165,12 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof indexRouteImport parentRoute: typeof rootRouteImport } - '/_layout/dashboard': { - id: '/_layout/dashboard' - path: '/dashboard' - fullPath: '/dashboard' - preLoaderRoute: typeof dbDashboardRouteImport - parentRoute: typeof layoutRoute + '/_layout': { + id: '/_layout' + path: '' + fullPath: '/' + preLoaderRoute: typeof layoutRouteImport + parentRoute: typeof rootRouteImport } '/$lang/': { id: '/$lang/' @@ -186,13 +179,20 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof pagesRouteImport parentRoute: typeof rootRouteImport } - '/_layout/hello/': { - id: '/_layout/hello/' - path: '/hello' - fullPath: '/hello/' - preLoaderRoute: typeof HelloIndexRouteImport + '/_layout/dashboard': { + id: '/_layout/dashboard' + path: '/dashboard' + fullPath: '/dashboard' + preLoaderRoute: typeof dbDashboardRouteImport parentRoute: typeof layoutRoute } + '/_layout/dashboard/': { + id: '/_layout/dashboard/' + path: '/' + fullPath: '/dashboard/' + preLoaderRoute: typeof dbDashboardIndexRouteImport + parentRoute: typeof dbDashboardRoute + } '/_layout/dashboard/invoices': { id: '/_layout/dashboard/invoices' path: '/invoices' @@ -200,12 +200,26 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof dbDashboardInvoicesRouteImport parentRoute: typeof dbDashboardRoute } - '/_layout/dashboard/': { - id: '/_layout/dashboard/' + '/_layout/hello/': { + id: '/_layout/hello/' + path: '/hello' + fullPath: '/hello/' + preLoaderRoute: typeof HelloIndexRouteImport + parentRoute: typeof layoutRoute + } + '/_layout/dashboard/invoices/': { + id: '/_layout/dashboard/invoices/' path: '/' - fullPath: '/dashboard/' - preLoaderRoute: typeof dbDashboardIndexRouteImport - parentRoute: typeof dbDashboardRoute + fullPath: '/dashboard/invoices/' + preLoaderRoute: typeof dbInvoicesIndexRouteImport + parentRoute: typeof dbDashboardInvoicesRoute + } + '/_layout/dashboard/invoices/$id': { + id: '/_layout/dashboard/invoices/$id' + path: '/$id' + fullPath: '/dashboard/invoices/$id' + preLoaderRoute: typeof dbInvoiceDetailRouteImport + parentRoute: typeof dbDashboardInvoicesRoute } '/_layout/hello/foo/': { id: '/_layout/hello/foo/' @@ -221,20 +235,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof HelloFooIdRouteImport parentRoute: typeof layoutRoute } - '/_layout/dashboard/invoices/$id': { - id: '/_layout/dashboard/invoices/$id' - path: '/$id' - fullPath: '/dashboard/invoices/$id' - preLoaderRoute: typeof dbInvoiceDetailRouteImport - parentRoute: typeof dbDashboardInvoicesRoute - } - '/_layout/dashboard/invoices/': { - id: '/_layout/dashboard/invoices/' - path: '/' - fullPath: '/dashboard/invoices/' - preLoaderRoute: typeof dbInvoicesIndexRouteImport - parentRoute: typeof dbDashboardInvoicesRoute - } } } diff --git a/packages/router-generator/tests/generator/virtual-config-file-named-export/routeTree.snapshot.ts b/packages/router-generator/tests/generator/virtual-config-file-named-export/routeTree.snapshot.ts index 3d3c2de9d5..6b16924d5b 100644 --- a/packages/router-generator/tests/generator/virtual-config-file-named-export/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/virtual-config-file-named-export/routeTree.snapshot.ts @@ -9,51 +9,61 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/root' -import { Route as layoutRouteImport } from './routes/layout' import { Route as indexRouteImport } from './routes/index' -import { Route as dbDashboardRouteImport } from './routes/db/dashboard' +import { Route as layoutRouteImport } from './routes/layout' import { Route as pagesRouteImport } from './routes/pages' -import { Route as HelloIndexRouteImport } from './routes/subtree/index' -import { Route as dbDashboardInvoicesRouteImport } from './routes/db/dashboard-invoices' +import { Route as dbDashboardRouteImport } from './routes/db/dashboard' import { Route as dbDashboardIndexRouteImport } from './routes/db/dashboard-index' +import { Route as dbDashboardInvoicesRouteImport } from './routes/db/dashboard-invoices' +import { Route as HelloIndexRouteImport } from './routes/subtree/index' +import { Route as dbInvoicesIndexRouteImport } from './routes/db/invoices-index' +import { Route as dbInvoiceDetailRouteImport } from './routes/db/invoice-detail' import { Route as HelloFooIndexRouteImport } from './routes/subtree/foo/index' import { Route as HelloFooIdRouteImport } from './routes/subtree/foo/$id' -import { Route as dbInvoiceDetailRouteImport } from './routes/db/invoice-detail' -import { Route as dbInvoicesIndexRouteImport } from './routes/db/invoices-index' -const layoutRoute = layoutRouteImport.update({ - id: '/_layout', - getParentRoute: () => rootRouteImport, -} as any) const indexRoute = indexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) -const dbDashboardRoute = dbDashboardRouteImport.update({ - id: '/dashboard', - path: '/dashboard', - getParentRoute: () => layoutRoute, +const layoutRoute = layoutRouteImport.update({ + id: '/_layout', + getParentRoute: () => rootRouteImport, } as any) const pagesRoute = pagesRouteImport.update({ id: '/$lang/', path: '/$lang/', getParentRoute: () => rootRouteImport, } as any) -const HelloIndexRoute = HelloIndexRouteImport.update({ - id: '/hello/', - path: '/hello/', +const dbDashboardRoute = dbDashboardRouteImport.update({ + id: '/dashboard', + path: '/dashboard', getParentRoute: () => layoutRoute, } as any) +const dbDashboardIndexRoute = dbDashboardIndexRouteImport.update({ + id: '/', + path: '/', + getParentRoute: () => dbDashboardRoute, +} as any) const dbDashboardInvoicesRoute = dbDashboardInvoicesRouteImport.update({ id: '/invoices', path: '/invoices', getParentRoute: () => dbDashboardRoute, } as any) -const dbDashboardIndexRoute = dbDashboardIndexRouteImport.update({ +const HelloIndexRoute = HelloIndexRouteImport.update({ + id: '/hello/', + path: '/hello/', + getParentRoute: () => layoutRoute, +} as any) +const dbInvoicesIndexRoute = dbInvoicesIndexRouteImport.update({ id: '/', path: '/', - getParentRoute: () => dbDashboardRoute, + getParentRoute: () => dbDashboardInvoicesRoute, +} as any) +const dbInvoiceDetailRoute = dbInvoiceDetailRouteImport.update({ + id: '/$id', + path: '/$id', + getParentRoute: () => dbDashboardInvoicesRoute, } as any) const HelloFooIndexRoute = HelloFooIndexRouteImport.update({ id: '/hello/foo/', @@ -65,16 +75,6 @@ const HelloFooIdRoute = HelloFooIdRouteImport.update({ path: '/hello/foo/$id', getParentRoute: () => layoutRoute, } as any) -const dbInvoiceDetailRoute = dbInvoiceDetailRouteImport.update({ - id: '/$id', - path: '/$id', - getParentRoute: () => dbDashboardInvoicesRoute, -} as any) -const dbInvoicesIndexRoute = dbInvoicesIndexRouteImport.update({ - id: '/', - path: '/', - getParentRoute: () => dbDashboardInvoicesRoute, -} as any) export interface FileRoutesByFullPath { '/': typeof indexRoute @@ -158,13 +158,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/_layout': { - id: '/_layout' - path: '' - fullPath: '/' - preLoaderRoute: typeof layoutRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -172,12 +165,12 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof indexRouteImport parentRoute: typeof rootRouteImport } - '/_layout/dashboard': { - id: '/_layout/dashboard' - path: '/dashboard' - fullPath: '/dashboard' - preLoaderRoute: typeof dbDashboardRouteImport - parentRoute: typeof layoutRoute + '/_layout': { + id: '/_layout' + path: '' + fullPath: '/' + preLoaderRoute: typeof layoutRouteImport + parentRoute: typeof rootRouteImport } '/$lang/': { id: '/$lang/' @@ -186,13 +179,20 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof pagesRouteImport parentRoute: typeof rootRouteImport } - '/_layout/hello/': { - id: '/_layout/hello/' - path: '/hello' - fullPath: '/hello/' - preLoaderRoute: typeof HelloIndexRouteImport + '/_layout/dashboard': { + id: '/_layout/dashboard' + path: '/dashboard' + fullPath: '/dashboard' + preLoaderRoute: typeof dbDashboardRouteImport parentRoute: typeof layoutRoute } + '/_layout/dashboard/': { + id: '/_layout/dashboard/' + path: '/' + fullPath: '/dashboard/' + preLoaderRoute: typeof dbDashboardIndexRouteImport + parentRoute: typeof dbDashboardRoute + } '/_layout/dashboard/invoices': { id: '/_layout/dashboard/invoices' path: '/invoices' @@ -200,12 +200,26 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof dbDashboardInvoicesRouteImport parentRoute: typeof dbDashboardRoute } - '/_layout/dashboard/': { - id: '/_layout/dashboard/' + '/_layout/hello/': { + id: '/_layout/hello/' + path: '/hello' + fullPath: '/hello/' + preLoaderRoute: typeof HelloIndexRouteImport + parentRoute: typeof layoutRoute + } + '/_layout/dashboard/invoices/': { + id: '/_layout/dashboard/invoices/' path: '/' - fullPath: '/dashboard/' - preLoaderRoute: typeof dbDashboardIndexRouteImport - parentRoute: typeof dbDashboardRoute + fullPath: '/dashboard/invoices/' + preLoaderRoute: typeof dbInvoicesIndexRouteImport + parentRoute: typeof dbDashboardInvoicesRoute + } + '/_layout/dashboard/invoices/$id': { + id: '/_layout/dashboard/invoices/$id' + path: '/$id' + fullPath: '/dashboard/invoices/$id' + preLoaderRoute: typeof dbInvoiceDetailRouteImport + parentRoute: typeof dbDashboardInvoicesRoute } '/_layout/hello/foo/': { id: '/_layout/hello/foo/' @@ -221,20 +235,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof HelloFooIdRouteImport parentRoute: typeof layoutRoute } - '/_layout/dashboard/invoices/$id': { - id: '/_layout/dashboard/invoices/$id' - path: '/$id' - fullPath: '/dashboard/invoices/$id' - preLoaderRoute: typeof dbInvoiceDetailRouteImport - parentRoute: typeof dbDashboardInvoicesRoute - } - '/_layout/dashboard/invoices/': { - id: '/_layout/dashboard/invoices/' - path: '/' - fullPath: '/dashboard/invoices/' - preLoaderRoute: typeof dbInvoicesIndexRouteImport - parentRoute: typeof dbDashboardInvoicesRoute - } } } diff --git a/packages/router-generator/tests/generator/virtual-config-file-tsconfig-paths/routeTree.snapshot.ts b/packages/router-generator/tests/generator/virtual-config-file-tsconfig-paths/routeTree.snapshot.ts index 3d3c2de9d5..6b16924d5b 100644 --- a/packages/router-generator/tests/generator/virtual-config-file-tsconfig-paths/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/virtual-config-file-tsconfig-paths/routeTree.snapshot.ts @@ -9,51 +9,61 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/root' -import { Route as layoutRouteImport } from './routes/layout' import { Route as indexRouteImport } from './routes/index' -import { Route as dbDashboardRouteImport } from './routes/db/dashboard' +import { Route as layoutRouteImport } from './routes/layout' import { Route as pagesRouteImport } from './routes/pages' -import { Route as HelloIndexRouteImport } from './routes/subtree/index' -import { Route as dbDashboardInvoicesRouteImport } from './routes/db/dashboard-invoices' +import { Route as dbDashboardRouteImport } from './routes/db/dashboard' import { Route as dbDashboardIndexRouteImport } from './routes/db/dashboard-index' +import { Route as dbDashboardInvoicesRouteImport } from './routes/db/dashboard-invoices' +import { Route as HelloIndexRouteImport } from './routes/subtree/index' +import { Route as dbInvoicesIndexRouteImport } from './routes/db/invoices-index' +import { Route as dbInvoiceDetailRouteImport } from './routes/db/invoice-detail' import { Route as HelloFooIndexRouteImport } from './routes/subtree/foo/index' import { Route as HelloFooIdRouteImport } from './routes/subtree/foo/$id' -import { Route as dbInvoiceDetailRouteImport } from './routes/db/invoice-detail' -import { Route as dbInvoicesIndexRouteImport } from './routes/db/invoices-index' -const layoutRoute = layoutRouteImport.update({ - id: '/_layout', - getParentRoute: () => rootRouteImport, -} as any) const indexRoute = indexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) -const dbDashboardRoute = dbDashboardRouteImport.update({ - id: '/dashboard', - path: '/dashboard', - getParentRoute: () => layoutRoute, +const layoutRoute = layoutRouteImport.update({ + id: '/_layout', + getParentRoute: () => rootRouteImport, } as any) const pagesRoute = pagesRouteImport.update({ id: '/$lang/', path: '/$lang/', getParentRoute: () => rootRouteImport, } as any) -const HelloIndexRoute = HelloIndexRouteImport.update({ - id: '/hello/', - path: '/hello/', +const dbDashboardRoute = dbDashboardRouteImport.update({ + id: '/dashboard', + path: '/dashboard', getParentRoute: () => layoutRoute, } as any) +const dbDashboardIndexRoute = dbDashboardIndexRouteImport.update({ + id: '/', + path: '/', + getParentRoute: () => dbDashboardRoute, +} as any) const dbDashboardInvoicesRoute = dbDashboardInvoicesRouteImport.update({ id: '/invoices', path: '/invoices', getParentRoute: () => dbDashboardRoute, } as any) -const dbDashboardIndexRoute = dbDashboardIndexRouteImport.update({ +const HelloIndexRoute = HelloIndexRouteImport.update({ + id: '/hello/', + path: '/hello/', + getParentRoute: () => layoutRoute, +} as any) +const dbInvoicesIndexRoute = dbInvoicesIndexRouteImport.update({ id: '/', path: '/', - getParentRoute: () => dbDashboardRoute, + getParentRoute: () => dbDashboardInvoicesRoute, +} as any) +const dbInvoiceDetailRoute = dbInvoiceDetailRouteImport.update({ + id: '/$id', + path: '/$id', + getParentRoute: () => dbDashboardInvoicesRoute, } as any) const HelloFooIndexRoute = HelloFooIndexRouteImport.update({ id: '/hello/foo/', @@ -65,16 +75,6 @@ const HelloFooIdRoute = HelloFooIdRouteImport.update({ path: '/hello/foo/$id', getParentRoute: () => layoutRoute, } as any) -const dbInvoiceDetailRoute = dbInvoiceDetailRouteImport.update({ - id: '/$id', - path: '/$id', - getParentRoute: () => dbDashboardInvoicesRoute, -} as any) -const dbInvoicesIndexRoute = dbInvoicesIndexRouteImport.update({ - id: '/', - path: '/', - getParentRoute: () => dbDashboardInvoicesRoute, -} as any) export interface FileRoutesByFullPath { '/': typeof indexRoute @@ -158,13 +158,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/_layout': { - id: '/_layout' - path: '' - fullPath: '/' - preLoaderRoute: typeof layoutRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -172,12 +165,12 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof indexRouteImport parentRoute: typeof rootRouteImport } - '/_layout/dashboard': { - id: '/_layout/dashboard' - path: '/dashboard' - fullPath: '/dashboard' - preLoaderRoute: typeof dbDashboardRouteImport - parentRoute: typeof layoutRoute + '/_layout': { + id: '/_layout' + path: '' + fullPath: '/' + preLoaderRoute: typeof layoutRouteImport + parentRoute: typeof rootRouteImport } '/$lang/': { id: '/$lang/' @@ -186,13 +179,20 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof pagesRouteImport parentRoute: typeof rootRouteImport } - '/_layout/hello/': { - id: '/_layout/hello/' - path: '/hello' - fullPath: '/hello/' - preLoaderRoute: typeof HelloIndexRouteImport + '/_layout/dashboard': { + id: '/_layout/dashboard' + path: '/dashboard' + fullPath: '/dashboard' + preLoaderRoute: typeof dbDashboardRouteImport parentRoute: typeof layoutRoute } + '/_layout/dashboard/': { + id: '/_layout/dashboard/' + path: '/' + fullPath: '/dashboard/' + preLoaderRoute: typeof dbDashboardIndexRouteImport + parentRoute: typeof dbDashboardRoute + } '/_layout/dashboard/invoices': { id: '/_layout/dashboard/invoices' path: '/invoices' @@ -200,12 +200,26 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof dbDashboardInvoicesRouteImport parentRoute: typeof dbDashboardRoute } - '/_layout/dashboard/': { - id: '/_layout/dashboard/' + '/_layout/hello/': { + id: '/_layout/hello/' + path: '/hello' + fullPath: '/hello/' + preLoaderRoute: typeof HelloIndexRouteImport + parentRoute: typeof layoutRoute + } + '/_layout/dashboard/invoices/': { + id: '/_layout/dashboard/invoices/' path: '/' - fullPath: '/dashboard/' - preLoaderRoute: typeof dbDashboardIndexRouteImport - parentRoute: typeof dbDashboardRoute + fullPath: '/dashboard/invoices/' + preLoaderRoute: typeof dbInvoicesIndexRouteImport + parentRoute: typeof dbDashboardInvoicesRoute + } + '/_layout/dashboard/invoices/$id': { + id: '/_layout/dashboard/invoices/$id' + path: '/$id' + fullPath: '/dashboard/invoices/$id' + preLoaderRoute: typeof dbInvoiceDetailRouteImport + parentRoute: typeof dbDashboardInvoicesRoute } '/_layout/hello/foo/': { id: '/_layout/hello/foo/' @@ -221,20 +235,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof HelloFooIdRouteImport parentRoute: typeof layoutRoute } - '/_layout/dashboard/invoices/$id': { - id: '/_layout/dashboard/invoices/$id' - path: '/$id' - fullPath: '/dashboard/invoices/$id' - preLoaderRoute: typeof dbInvoiceDetailRouteImport - parentRoute: typeof dbDashboardInvoicesRoute - } - '/_layout/dashboard/invoices/': { - id: '/_layout/dashboard/invoices/' - path: '/' - fullPath: '/dashboard/invoices/' - preLoaderRoute: typeof dbInvoicesIndexRouteImport - parentRoute: typeof dbDashboardInvoicesRoute - } } } diff --git a/packages/router-generator/tests/generator/virtual-inside-nested/routeTree.snapshot.ts b/packages/router-generator/tests/generator/virtual-inside-nested/routeTree.snapshot.ts index 9f60b82e06..37de7dc290 100644 --- a/packages/router-generator/tests/generator/virtual-inside-nested/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/virtual-inside-nested/routeTree.snapshot.ts @@ -11,8 +11,8 @@ import { Route as rootRouteImport } from './routes/__root' import { Route as IndexRouteImport } from './routes/index' import { Route as FooBarRouteImport } from './routes/foo/bar' -import { Route as FooBarDetailsRouteImport } from './routes/foo/bar/details' import { Route as FooBarHomeRouteImport } from './routes/foo/bar/home' +import { Route as FooBarDetailsRouteImport } from './routes/foo/bar/details' const IndexRoute = IndexRouteImport.update({ id: '/', @@ -24,16 +24,16 @@ const FooBarRoute = FooBarRouteImport.update({ path: '/foo/bar', getParentRoute: () => rootRouteImport, } as any) -const FooBarDetailsRoute = FooBarDetailsRouteImport.update({ - id: '/$id', - path: '/$id', - getParentRoute: () => FooBarRoute, -} as any) const FooBarHomeRoute = FooBarHomeRouteImport.update({ id: '/', path: '/', getParentRoute: () => FooBarRoute, } as any) +const FooBarDetailsRoute = FooBarDetailsRouteImport.update({ + id: '/$id', + path: '/$id', + getParentRoute: () => FooBarRoute, +} as any) export interface FileRoutesByFullPath { '/': typeof IndexRoute @@ -82,13 +82,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof FooBarRouteImport parentRoute: typeof rootRouteImport } - '/foo/bar/$id': { - id: '/foo/bar/$id' - path: '/$id' - fullPath: '/foo/bar/$id' - preLoaderRoute: typeof FooBarDetailsRouteImport - parentRoute: typeof FooBarRoute - } '/foo/bar/': { id: '/foo/bar/' path: '/' @@ -96,6 +89,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof FooBarHomeRouteImport parentRoute: typeof FooBarRoute } + '/foo/bar/$id': { + id: '/foo/bar/$id' + path: '/$id' + fullPath: '/foo/bar/$id' + preLoaderRoute: typeof FooBarDetailsRouteImport + parentRoute: typeof FooBarRoute + } } } diff --git a/packages/router-generator/tests/generator/virtual-inside-with-escaped-underscore/routeTree.snapshot.ts b/packages/router-generator/tests/generator/virtual-inside-with-escaped-underscore/routeTree.snapshot.ts index 664cea729c..340a1f0f5e 100644 --- a/packages/router-generator/tests/generator/virtual-inside-with-escaped-underscore/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/virtual-inside-with-escaped-underscore/routeTree.snapshot.ts @@ -10,18 +10,18 @@ import { Route as rootRouteImport } from './routes/__root' import { Route as IndexRouteImport } from './routes/index' -import { Route as NestedCallbackRouteImport } from './routes/nested/callback' -import { Route as NestedAuthRouteImport } from './routes/nested/auth' import { Route as NestedHomeRouteImport } from './routes/nested/home' +import { Route as NestedAuthRouteImport } from './routes/nested/auth' +import { Route as NestedCallbackRouteImport } from './routes/nested/callback' const IndexRoute = IndexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) -const NestedCallbackRoute = NestedCallbackRouteImport.update({ - id: '/nested/_callback', - path: '/nested/_callback', +const NestedHomeRoute = NestedHomeRouteImport.update({ + id: '/nested/', + path: '/nested/', getParentRoute: () => rootRouteImport, } as any) const NestedAuthRoute = NestedAuthRouteImport.update({ @@ -29,9 +29,9 @@ const NestedAuthRoute = NestedAuthRouteImport.update({ path: '/nested/_auth', getParentRoute: () => rootRouteImport, } as any) -const NestedHomeRoute = NestedHomeRouteImport.update({ - id: '/nested/', - path: '/nested/', +const NestedCallbackRoute = NestedCallbackRouteImport.update({ + id: '/nested/_callback', + path: '/nested/_callback', getParentRoute: () => rootRouteImport, } as any) @@ -78,11 +78,11 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } - '/nested/_callback': { - id: '/nested/_callback' - path: '/nested/_callback' - fullPath: '/nested/_callback' - preLoaderRoute: typeof NestedCallbackRouteImport + '/nested/': { + id: '/nested/' + path: '/nested' + fullPath: '/nested/' + preLoaderRoute: typeof NestedHomeRouteImport parentRoute: typeof rootRouteImport } '/nested/_auth': { @@ -92,11 +92,11 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof NestedAuthRouteImport parentRoute: typeof rootRouteImport } - '/nested/': { - id: '/nested/' - path: '/nested' - fullPath: '/nested/' - preLoaderRoute: typeof NestedHomeRouteImport + '/nested/_callback': { + id: '/nested/_callback' + path: '/nested/_callback' + fullPath: '/nested/_callback' + preLoaderRoute: typeof NestedCallbackRouteImport parentRoute: typeof rootRouteImport } } diff --git a/packages/router-generator/tests/generator/virtual-nested-layouts-with-virtual-route/routeTree.snapshot.ts b/packages/router-generator/tests/generator/virtual-nested-layouts-with-virtual-route/routeTree.snapshot.ts index e991cd3964..7268f402ae 100644 --- a/packages/router-generator/tests/generator/virtual-nested-layouts-with-virtual-route/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/virtual-nested-layouts-with-virtual-route/routeTree.snapshot.ts @@ -9,35 +9,35 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as layoutFirstLayoutRouteImport } from './routes/layout/first-layout' import { Route as homeRouteImport } from './routes/home' +import { Route as layoutFirstLayoutRouteImport } from './routes/layout/first-layout' import { Route as layoutSecondLayoutRouteImport } from './routes/layout/second-layout' -import { Route as bRouteImport } from './routes/b' import { Route as aRouteImport } from './routes/a' +import { Route as bRouteImport } from './routes/b' -const layoutFirstLayoutRoute = layoutFirstLayoutRouteImport.update({ - id: '/_first', - getParentRoute: () => rootRouteImport, -} as any) const homeRoute = homeRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) +const layoutFirstLayoutRoute = layoutFirstLayoutRouteImport.update({ + id: '/_first', + getParentRoute: () => rootRouteImport, +} as any) const layoutSecondLayoutRoute = layoutSecondLayoutRouteImport.update({ id: '/_second-layout', getParentRoute: () => layoutFirstLayoutRoute, } as any) -const bRoute = bRouteImport.update({ - id: '/route-without-file/layout-b', - path: '/route-without-file/layout-b', - getParentRoute: () => layoutSecondLayoutRoute, -} as any) const aRoute = aRouteImport.update({ id: '/route-without-file/layout-a', path: '/route-without-file/layout-a', getParentRoute: () => layoutSecondLayoutRoute, } as any) +const bRoute = bRouteImport.update({ + id: '/route-without-file/layout-b', + path: '/route-without-file/layout-b', + getParentRoute: () => layoutSecondLayoutRoute, +} as any) export interface FileRoutesByFullPath { '/': typeof homeRoute @@ -81,13 +81,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/_first': { - id: '/_first' - path: '' - fullPath: '/' - preLoaderRoute: typeof layoutFirstLayoutRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -95,6 +88,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof homeRouteImport parentRoute: typeof rootRouteImport } + '/_first': { + id: '/_first' + path: '' + fullPath: '/' + preLoaderRoute: typeof layoutFirstLayoutRouteImport + parentRoute: typeof rootRouteImport + } '/_first/_second-layout': { id: '/_first/_second-layout' path: '' @@ -102,13 +102,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof layoutSecondLayoutRouteImport parentRoute: typeof layoutFirstLayoutRoute } - '/_first/_second-layout/route-without-file/layout-b': { - id: '/_first/_second-layout/route-without-file/layout-b' - path: '/route-without-file/layout-b' - fullPath: '/route-without-file/layout-b' - preLoaderRoute: typeof bRouteImport - parentRoute: typeof layoutSecondLayoutRoute - } '/_first/_second-layout/route-without-file/layout-a': { id: '/_first/_second-layout/route-without-file/layout-a' path: '/route-without-file/layout-a' @@ -116,6 +109,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof aRouteImport parentRoute: typeof layoutSecondLayoutRoute } + '/_first/_second-layout/route-without-file/layout-b': { + id: '/_first/_second-layout/route-without-file/layout-b' + path: '/route-without-file/layout-b' + fullPath: '/route-without-file/layout-b' + preLoaderRoute: typeof bRouteImport + parentRoute: typeof layoutSecondLayoutRoute + } } } diff --git a/packages/router-generator/tests/generator/virtual-pathless-layout-escaped-underscore/routeTree.snapshot.ts b/packages/router-generator/tests/generator/virtual-pathless-layout-escaped-underscore/routeTree.snapshot.ts index 70d06b2004..ec20742d1e 100644 --- a/packages/router-generator/tests/generator/virtual-pathless-layout-escaped-underscore/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/virtual-pathless-layout-escaped-underscore/routeTree.snapshot.ts @@ -9,34 +9,30 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as layoutRouteImport } from './routes/layout' -import { Route as fooRouteImport } from './routes/foo' -import { Route as escapedRouteImport } from './routes/escaped' import { Route as doubleRouteImport } from './routes/double' -import { Route as rootIdRouteImport } from './routes/root-id' -import { Route as nestedLayoutRouteImport } from './routes/nested-layout' -import { Route as innerLayoutRouteImport } from './routes/inner-layout' -import { Route as escapedBarRouteImport } from './routes/escaped-bar' -import { Route as barRouteImport } from './routes/bar' +import { Route as escapedRouteImport } from './routes/escaped' +import { Route as fooRouteImport } from './routes/foo' +import { Route as layoutRouteImport } from './routes/layout' import { Route as doubleBarRouteImport } from './routes/double-bar' +import { Route as barRouteImport } from './routes/bar' +import { Route as escapedBarRouteImport } from './routes/escaped-bar' +import { Route as innerLayoutRouteImport } from './routes/inner-layout' +import { Route as nestedLayoutRouteImport } from './routes/nested-layout' import { Route as rootIndexRouteImport } from './routes/root-index' -import { Route as bazRouteImport } from './routes/baz' -import { Route as nestedIdRouteImport } from './routes/nested-id' -import { Route as escapedIdRouteImport } from './routes/escaped-id' +import { Route as rootIdRouteImport } from './routes/root-id' +import { Route as doubleIndexRouteImport } from './routes/double-index' import { Route as doubleIdRouteImport } from './routes/double-id' -import { Route as trailIndexRouteImport } from './routes/trail-index' -import { Route as nestedIndexRouteImport } from './routes/nested-index' import { Route as escapedIndexRouteImport } from './routes/escaped-index' -import { Route as doubleIndexRouteImport } from './routes/double-index' +import { Route as escapedIdRouteImport } from './routes/escaped-id' +import { Route as nestedIndexRouteImport } from './routes/nested-index' +import { Route as nestedIdRouteImport } from './routes/nested-id' +import { Route as bazRouteImport } from './routes/baz' +import { Route as trailIndexRouteImport } from './routes/trail-index' import { Route as deepIndexRouteImport } from './routes/deep-index' -const layoutRoute = layoutRouteImport.update({ - id: '/_layout', - getParentRoute: () => rootRouteImport, -} as any) -const fooRoute = fooRouteImport.update({ - id: '/_foo', - path: '/_foo', +const doubleRoute = doubleRouteImport.update({ + id: '/__double', + path: '/__double', getParentRoute: () => rootRouteImport, } as any) const escapedRoute = escapedRouteImport.update({ @@ -44,22 +40,23 @@ const escapedRoute = escapedRouteImport.update({ path: '/_escaped', getParentRoute: () => rootRouteImport, } as any) -const doubleRoute = doubleRouteImport.update({ - id: '/__double', - path: '/__double', +const fooRoute = fooRouteImport.update({ + id: '/_foo', + path: '/_foo', getParentRoute: () => rootRouteImport, } as any) -const rootIdRoute = rootIdRouteImport.update({ - id: '/_root-index/$id', - path: '/_root-index/$id', +const layoutRoute = layoutRouteImport.update({ + id: '/_layout', getParentRoute: () => rootRouteImport, } as any) -const nestedLayoutRoute = nestedLayoutRouteImport.update({ - id: '/_nested', +const doubleBarRoute = doubleBarRouteImport.update({ + id: '/__double-bar', + path: '/__double-bar', getParentRoute: () => layoutRoute, } as any) -const innerLayoutRoute = innerLayoutRouteImport.update({ - id: '/_inner', +const barRoute = barRouteImport.update({ + id: '/_bar', + path: '/_bar', getParentRoute: () => layoutRoute, } as any) const escapedBarRoute = escapedBarRouteImport.update({ @@ -67,14 +64,12 @@ const escapedBarRoute = escapedBarRouteImport.update({ path: '/_escaped-bar', getParentRoute: () => layoutRoute, } as any) -const barRoute = barRouteImport.update({ - id: '/_bar', - path: '/_bar', +const innerLayoutRoute = innerLayoutRouteImport.update({ + id: '/_inner', getParentRoute: () => layoutRoute, } as any) -const doubleBarRoute = doubleBarRouteImport.update({ - id: '/__double-bar', - path: '/__double-bar', +const nestedLayoutRoute = nestedLayoutRouteImport.update({ + id: '/_nested', getParentRoute: () => layoutRoute, } as any) const rootIndexRoute = rootIndexRouteImport.update({ @@ -82,19 +77,14 @@ const rootIndexRoute = rootIndexRouteImport.update({ path: '/_root-index/', getParentRoute: () => rootRouteImport, } as any) -const bazRoute = bazRouteImport.update({ - id: '/_baz', - path: '/_baz', - getParentRoute: () => nestedLayoutRoute, -} as any) -const nestedIdRoute = nestedIdRouteImport.update({ - id: '/_nested-index/$id', - path: '/_nested-index/$id', - getParentRoute: () => layoutRoute, +const rootIdRoute = rootIdRouteImport.update({ + id: '/_root-index/$id', + path: '/_root-index/$id', + getParentRoute: () => rootRouteImport, } as any) -const escapedIdRoute = escapedIdRouteImport.update({ - id: '/_escaped-index/$id', - path: '/_escaped-index/$id', +const doubleIndexRoute = doubleIndexRouteImport.update({ + id: '/__double-index/', + path: '/__double-index/', getParentRoute: () => layoutRoute, } as any) const doubleIdRoute = doubleIdRouteImport.update({ @@ -102,9 +92,14 @@ const doubleIdRoute = doubleIdRouteImport.update({ path: '/__double-index/$id', getParentRoute: () => layoutRoute, } as any) -const trailIndexRoute = trailIndexRouteImport.update({ - id: '/trail_/', - path: '/trail_/', +const escapedIndexRoute = escapedIndexRouteImport.update({ + id: '/_escaped-index/', + path: '/_escaped-index/', + getParentRoute: () => layoutRoute, +} as any) +const escapedIdRoute = escapedIdRouteImport.update({ + id: '/_escaped-index/$id', + path: '/_escaped-index/$id', getParentRoute: () => layoutRoute, } as any) const nestedIndexRoute = nestedIndexRouteImport.update({ @@ -112,14 +107,19 @@ const nestedIndexRoute = nestedIndexRouteImport.update({ path: '/_nested-index/', getParentRoute: () => layoutRoute, } as any) -const escapedIndexRoute = escapedIndexRouteImport.update({ - id: '/_escaped-index/', - path: '/_escaped-index/', +const nestedIdRoute = nestedIdRouteImport.update({ + id: '/_nested-index/$id', + path: '/_nested-index/$id', getParentRoute: () => layoutRoute, } as any) -const doubleIndexRoute = doubleIndexRouteImport.update({ - id: '/__double-index/', - path: '/__double-index/', +const bazRoute = bazRouteImport.update({ + id: '/_baz', + path: '/_baz', + getParentRoute: () => nestedLayoutRoute, +} as any) +const trailIndexRoute = trailIndexRouteImport.update({ + id: '/trail_/', + path: '/trail_/', getParentRoute: () => layoutRoute, } as any) const deepIndexRoute = deepIndexRouteImport.update({ @@ -267,18 +267,11 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/_layout': { - id: '/_layout' - path: '' - fullPath: '/' - preLoaderRoute: typeof layoutRouteImport - parentRoute: typeof rootRouteImport - } - '/_foo': { - id: '/_foo' - path: '/_foo' - fullPath: '/_foo' - preLoaderRoute: typeof fooRouteImport + '/__double': { + id: '/__double' + path: '/__double' + fullPath: '/__double' + preLoaderRoute: typeof doubleRouteImport parentRoute: typeof rootRouteImport } '/_escaped': { @@ -288,32 +281,32 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof escapedRouteImport parentRoute: typeof rootRouteImport } - '/__double': { - id: '/__double' - path: '/__double' - fullPath: '/__double' - preLoaderRoute: typeof doubleRouteImport - parentRoute: typeof rootRouteImport - } - '/_root-index/$id': { - id: '/_root-index/$id' - path: '/_root-index/$id' - fullPath: '/_root-index/$id' - preLoaderRoute: typeof rootIdRouteImport + '/_foo': { + id: '/_foo' + path: '/_foo' + fullPath: '/_foo' + preLoaderRoute: typeof fooRouteImport parentRoute: typeof rootRouteImport } - '/_layout/_nested': { - id: '/_layout/_nested' + '/_layout': { + id: '/_layout' path: '' fullPath: '/' - preLoaderRoute: typeof nestedLayoutRouteImport + preLoaderRoute: typeof layoutRouteImport + parentRoute: typeof rootRouteImport + } + '/_layout/__double-bar': { + id: '/_layout/__double-bar' + path: '/__double-bar' + fullPath: '/__double-bar' + preLoaderRoute: typeof doubleBarRouteImport parentRoute: typeof layoutRoute } - '/_layout/_inner': { - id: '/_layout/_inner' - path: '' - fullPath: '/' - preLoaderRoute: typeof innerLayoutRouteImport + '/_layout/_bar': { + id: '/_layout/_bar' + path: '/_bar' + fullPath: '/_bar' + preLoaderRoute: typeof barRouteImport parentRoute: typeof layoutRoute } '/_layout/_escaped-bar': { @@ -323,18 +316,18 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof escapedBarRouteImport parentRoute: typeof layoutRoute } - '/_layout/_bar': { - id: '/_layout/_bar' - path: '/_bar' - fullPath: '/_bar' - preLoaderRoute: typeof barRouteImport + '/_layout/_inner': { + id: '/_layout/_inner' + path: '' + fullPath: '/' + preLoaderRoute: typeof innerLayoutRouteImport parentRoute: typeof layoutRoute } - '/_layout/__double-bar': { - id: '/_layout/__double-bar' - path: '/__double-bar' - fullPath: '/__double-bar' - preLoaderRoute: typeof doubleBarRouteImport + '/_layout/_nested': { + id: '/_layout/_nested' + path: '' + fullPath: '/' + preLoaderRoute: typeof nestedLayoutRouteImport parentRoute: typeof layoutRoute } '/_root-index/': { @@ -344,25 +337,18 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof rootIndexRouteImport parentRoute: typeof rootRouteImport } - '/_layout/_nested/_baz': { - id: '/_layout/_nested/_baz' - path: '/_baz' - fullPath: '/_baz' - preLoaderRoute: typeof bazRouteImport - parentRoute: typeof nestedLayoutRoute - } - '/_layout/_nested-index/$id': { - id: '/_layout/_nested-index/$id' - path: '/_nested-index/$id' - fullPath: '/_nested-index/$id' - preLoaderRoute: typeof nestedIdRouteImport - parentRoute: typeof layoutRoute + '/_root-index/$id': { + id: '/_root-index/$id' + path: '/_root-index/$id' + fullPath: '/_root-index/$id' + preLoaderRoute: typeof rootIdRouteImport + parentRoute: typeof rootRouteImport } - '/_layout/_escaped-index/$id': { - id: '/_layout/_escaped-index/$id' - path: '/_escaped-index/$id' - fullPath: '/_escaped-index/$id' - preLoaderRoute: typeof escapedIdRouteImport + '/_layout/__double-index/': { + id: '/_layout/__double-index/' + path: '/__double-index' + fullPath: '/__double-index/' + preLoaderRoute: typeof doubleIndexRouteImport parentRoute: typeof layoutRoute } '/_layout/__double-index/$id': { @@ -372,11 +358,18 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof doubleIdRouteImport parentRoute: typeof layoutRoute } - '/_layout/trail_/': { - id: '/_layout/trail_/' - path: '/trail_' - fullPath: '/trail_/' - preLoaderRoute: typeof trailIndexRouteImport + '/_layout/_escaped-index/': { + id: '/_layout/_escaped-index/' + path: '/_escaped-index' + fullPath: '/_escaped-index/' + preLoaderRoute: typeof escapedIndexRouteImport + parentRoute: typeof layoutRoute + } + '/_layout/_escaped-index/$id': { + id: '/_layout/_escaped-index/$id' + path: '/_escaped-index/$id' + fullPath: '/_escaped-index/$id' + preLoaderRoute: typeof escapedIdRouteImport parentRoute: typeof layoutRoute } '/_layout/_nested-index/': { @@ -386,18 +379,25 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof nestedIndexRouteImport parentRoute: typeof layoutRoute } - '/_layout/_escaped-index/': { - id: '/_layout/_escaped-index/' - path: '/_escaped-index' - fullPath: '/_escaped-index/' - preLoaderRoute: typeof escapedIndexRouteImport + '/_layout/_nested-index/$id': { + id: '/_layout/_nested-index/$id' + path: '/_nested-index/$id' + fullPath: '/_nested-index/$id' + preLoaderRoute: typeof nestedIdRouteImport parentRoute: typeof layoutRoute } - '/_layout/__double-index/': { - id: '/_layout/__double-index/' - path: '/__double-index' - fullPath: '/__double-index/' - preLoaderRoute: typeof doubleIndexRouteImport + '/_layout/_nested/_baz': { + id: '/_layout/_nested/_baz' + path: '/_baz' + fullPath: '/_baz' + preLoaderRoute: typeof bazRouteImport + parentRoute: typeof nestedLayoutRoute + } + '/_layout/trail_/': { + id: '/_layout/trail_/' + path: '/trail_' + fullPath: '/trail_/' + preLoaderRoute: typeof trailIndexRouteImport parentRoute: typeof layoutRoute } '/_layout/_inner/_deep-index/': { diff --git a/packages/router-generator/tests/generator/virtual-physical-empty-path-merge/routeTree.snapshot.ts b/packages/router-generator/tests/generator/virtual-physical-empty-path-merge/routeTree.snapshot.ts index 6de1ed6975..eeb3c71359 100644 --- a/packages/router-generator/tests/generator/virtual-physical-empty-path-merge/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/virtual-physical-empty-path-merge/routeTree.snapshot.ts @@ -9,13 +9,13 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as ContactRouteImport } from './routes/merged/contact' -import { Route as aboutRouteImport } from './routes/about' import { Route as IndexRouteImport } from './routes/merged/index' +import { Route as aboutRouteImport } from './routes/about' +import { Route as ContactRouteImport } from './routes/merged/contact' -const ContactRoute = ContactRouteImport.update({ - id: '/contact', - path: '/contact', +const IndexRoute = IndexRouteImport.update({ + id: '/', + path: '/', getParentRoute: () => rootRouteImport, } as any) const aboutRoute = aboutRouteImport.update({ @@ -23,9 +23,9 @@ const aboutRoute = aboutRouteImport.update({ path: '/about', getParentRoute: () => rootRouteImport, } as any) -const IndexRoute = IndexRouteImport.update({ - id: '/', - path: '/', +const ContactRoute = ContactRouteImport.update({ + id: '/contact', + path: '/contact', getParentRoute: () => rootRouteImport, } as any) @@ -61,11 +61,11 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/contact': { - id: '/contact' - path: '/contact' - fullPath: '/contact' - preLoaderRoute: typeof ContactRouteImport + '/': { + id: '/' + path: '/' + fullPath: '/' + preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } '/about': { @@ -75,11 +75,11 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof aboutRouteImport parentRoute: typeof rootRouteImport } - '/': { - id: '/' - path: '/' - fullPath: '/' - preLoaderRoute: typeof IndexRouteImport + '/contact': { + id: '/contact' + path: '/contact' + fullPath: '/contact' + preLoaderRoute: typeof ContactRouteImport parentRoute: typeof rootRouteImport } } diff --git a/packages/router-generator/tests/generator/virtual-physical-layout-and-index/routeTree.snapshot.ts b/packages/router-generator/tests/generator/virtual-physical-layout-and-index/routeTree.snapshot.ts index bade75773c..e8cddcbc9c 100644 --- a/packages/router-generator/tests/generator/virtual-physical-layout-and-index/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/virtual-physical-layout-and-index/routeTree.snapshot.ts @@ -9,20 +9,20 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as FeatureRouteRouteImport } from './routes/feature/route' import { Route as indexRouteImport } from './routes/index' +import { Route as FeatureRouteRouteImport } from './routes/feature/route' import { Route as FeatureIndexRouteImport } from './routes/feature/index' -const FeatureRouteRoute = FeatureRouteRouteImport.update({ - id: '/feature', - path: '/feature', - getParentRoute: () => rootRouteImport, -} as any) const indexRoute = indexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) +const FeatureRouteRoute = FeatureRouteRouteImport.update({ + id: '/feature', + path: '/feature', + getParentRoute: () => rootRouteImport, +} as any) const FeatureIndexRoute = FeatureIndexRouteImport.update({ id: '/', path: '/', @@ -59,13 +59,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/feature': { - id: '/feature' - path: '/feature' - fullPath: '/feature' - preLoaderRoute: typeof FeatureRouteRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -73,6 +66,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof indexRouteImport parentRoute: typeof rootRouteImport } + '/feature': { + id: '/feature' + path: '/feature' + fullPath: '/feature' + preLoaderRoute: typeof FeatureRouteRouteImport + parentRoute: typeof rootRouteImport + } '/feature/': { id: '/feature/' path: '/' diff --git a/packages/router-generator/tests/generator/virtual-physical-no-prefix/routeTree.snapshot.ts b/packages/router-generator/tests/generator/virtual-physical-no-prefix/routeTree.snapshot.ts index 6de1ed6975..eeb3c71359 100644 --- a/packages/router-generator/tests/generator/virtual-physical-no-prefix/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/virtual-physical-no-prefix/routeTree.snapshot.ts @@ -9,13 +9,13 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/__root' -import { Route as ContactRouteImport } from './routes/merged/contact' -import { Route as aboutRouteImport } from './routes/about' import { Route as IndexRouteImport } from './routes/merged/index' +import { Route as aboutRouteImport } from './routes/about' +import { Route as ContactRouteImport } from './routes/merged/contact' -const ContactRoute = ContactRouteImport.update({ - id: '/contact', - path: '/contact', +const IndexRoute = IndexRouteImport.update({ + id: '/', + path: '/', getParentRoute: () => rootRouteImport, } as any) const aboutRoute = aboutRouteImport.update({ @@ -23,9 +23,9 @@ const aboutRoute = aboutRouteImport.update({ path: '/about', getParentRoute: () => rootRouteImport, } as any) -const IndexRoute = IndexRouteImport.update({ - id: '/', - path: '/', +const ContactRoute = ContactRouteImport.update({ + id: '/contact', + path: '/contact', getParentRoute: () => rootRouteImport, } as any) @@ -61,11 +61,11 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/contact': { - id: '/contact' - path: '/contact' - fullPath: '/contact' - preLoaderRoute: typeof ContactRouteImport + '/': { + id: '/' + path: '/' + fullPath: '/' + preLoaderRoute: typeof IndexRouteImport parentRoute: typeof rootRouteImport } '/about': { @@ -75,11 +75,11 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof aboutRouteImport parentRoute: typeof rootRouteImport } - '/': { - id: '/' - path: '/' - fullPath: '/' - preLoaderRoute: typeof IndexRouteImport + '/contact': { + id: '/contact' + path: '/contact' + fullPath: '/contact' + preLoaderRoute: typeof ContactRouteImport parentRoute: typeof rootRouteImport } } diff --git a/packages/router-generator/tests/generator/virtual-with-escaped-underscore/routeTree.snapshot.ts b/packages/router-generator/tests/generator/virtual-with-escaped-underscore/routeTree.snapshot.ts index 8eed55a7fe..18d7439610 100644 --- a/packages/router-generator/tests/generator/virtual-with-escaped-underscore/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/virtual-with-escaped-underscore/routeTree.snapshot.ts @@ -11,8 +11,8 @@ import { Route as rootRouteImport } from './routes/__root' import { Route as indexRouteImport } from './routes/index' import { Route as ApiIndexRouteImport } from './routes/physical-routes/index' -import { Route as ApiChar91_Char93helloRouteImport } from './routes/physical-routes/[_]hello' import { Route as ApiChar91_Char93authDotrouteRouteImport } from './routes/physical-routes/[_]auth.route' +import { Route as ApiChar91_Char93helloRouteImport } from './routes/physical-routes/[_]hello' const indexRoute = indexRouteImport.update({ id: '/', @@ -24,17 +24,17 @@ const ApiIndexRoute = ApiIndexRouteImport.update({ path: '/api/', getParentRoute: () => rootRouteImport, } as any) -const ApiChar91_Char93helloRoute = ApiChar91_Char93helloRouteImport.update({ - id: '/api/_hello', - path: '/api/_hello', - getParentRoute: () => rootRouteImport, -} as any) const ApiChar91_Char93authDotrouteRoute = ApiChar91_Char93authDotrouteRouteImport.update({ id: '/api/_auth', path: '/api/_auth', getParentRoute: () => rootRouteImport, } as any) +const ApiChar91_Char93helloRoute = ApiChar91_Char93helloRouteImport.update({ + id: '/api/_hello', + path: '/api/_hello', + getParentRoute: () => rootRouteImport, +} as any) export interface FileRoutesByFullPath { '/': typeof indexRoute @@ -86,13 +86,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof ApiIndexRouteImport parentRoute: typeof rootRouteImport } - '/api/_hello': { - id: '/api/_hello' - path: '/api/_hello' - fullPath: '/api/_hello' - preLoaderRoute: typeof ApiChar91_Char93helloRouteImport - parentRoute: typeof rootRouteImport - } '/api/_auth': { id: '/api/_auth' path: '/api/_auth' @@ -100,6 +93,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof ApiChar91_Char93authDotrouteRouteImport parentRoute: typeof rootRouteImport } + '/api/_hello': { + id: '/api/_hello' + path: '/api/_hello' + fullPath: '/api/_hello' + preLoaderRoute: typeof ApiChar91_Char93helloRouteImport + parentRoute: typeof rootRouteImport + } } } diff --git a/packages/router-generator/tests/generator/virtual/routeTree.snapshot.ts b/packages/router-generator/tests/generator/virtual/routeTree.snapshot.ts index 3d3c2de9d5..6b16924d5b 100644 --- a/packages/router-generator/tests/generator/virtual/routeTree.snapshot.ts +++ b/packages/router-generator/tests/generator/virtual/routeTree.snapshot.ts @@ -9,51 +9,61 @@ // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. import { Route as rootRouteImport } from './routes/root' -import { Route as layoutRouteImport } from './routes/layout' import { Route as indexRouteImport } from './routes/index' -import { Route as dbDashboardRouteImport } from './routes/db/dashboard' +import { Route as layoutRouteImport } from './routes/layout' import { Route as pagesRouteImport } from './routes/pages' -import { Route as HelloIndexRouteImport } from './routes/subtree/index' -import { Route as dbDashboardInvoicesRouteImport } from './routes/db/dashboard-invoices' +import { Route as dbDashboardRouteImport } from './routes/db/dashboard' import { Route as dbDashboardIndexRouteImport } from './routes/db/dashboard-index' +import { Route as dbDashboardInvoicesRouteImport } from './routes/db/dashboard-invoices' +import { Route as HelloIndexRouteImport } from './routes/subtree/index' +import { Route as dbInvoicesIndexRouteImport } from './routes/db/invoices-index' +import { Route as dbInvoiceDetailRouteImport } from './routes/db/invoice-detail' import { Route as HelloFooIndexRouteImport } from './routes/subtree/foo/index' import { Route as HelloFooIdRouteImport } from './routes/subtree/foo/$id' -import { Route as dbInvoiceDetailRouteImport } from './routes/db/invoice-detail' -import { Route as dbInvoicesIndexRouteImport } from './routes/db/invoices-index' -const layoutRoute = layoutRouteImport.update({ - id: '/_layout', - getParentRoute: () => rootRouteImport, -} as any) const indexRoute = indexRouteImport.update({ id: '/', path: '/', getParentRoute: () => rootRouteImport, } as any) -const dbDashboardRoute = dbDashboardRouteImport.update({ - id: '/dashboard', - path: '/dashboard', - getParentRoute: () => layoutRoute, +const layoutRoute = layoutRouteImport.update({ + id: '/_layout', + getParentRoute: () => rootRouteImport, } as any) const pagesRoute = pagesRouteImport.update({ id: '/$lang/', path: '/$lang/', getParentRoute: () => rootRouteImport, } as any) -const HelloIndexRoute = HelloIndexRouteImport.update({ - id: '/hello/', - path: '/hello/', +const dbDashboardRoute = dbDashboardRouteImport.update({ + id: '/dashboard', + path: '/dashboard', getParentRoute: () => layoutRoute, } as any) +const dbDashboardIndexRoute = dbDashboardIndexRouteImport.update({ + id: '/', + path: '/', + getParentRoute: () => dbDashboardRoute, +} as any) const dbDashboardInvoicesRoute = dbDashboardInvoicesRouteImport.update({ id: '/invoices', path: '/invoices', getParentRoute: () => dbDashboardRoute, } as any) -const dbDashboardIndexRoute = dbDashboardIndexRouteImport.update({ +const HelloIndexRoute = HelloIndexRouteImport.update({ + id: '/hello/', + path: '/hello/', + getParentRoute: () => layoutRoute, +} as any) +const dbInvoicesIndexRoute = dbInvoicesIndexRouteImport.update({ id: '/', path: '/', - getParentRoute: () => dbDashboardRoute, + getParentRoute: () => dbDashboardInvoicesRoute, +} as any) +const dbInvoiceDetailRoute = dbInvoiceDetailRouteImport.update({ + id: '/$id', + path: '/$id', + getParentRoute: () => dbDashboardInvoicesRoute, } as any) const HelloFooIndexRoute = HelloFooIndexRouteImport.update({ id: '/hello/foo/', @@ -65,16 +75,6 @@ const HelloFooIdRoute = HelloFooIdRouteImport.update({ path: '/hello/foo/$id', getParentRoute: () => layoutRoute, } as any) -const dbInvoiceDetailRoute = dbInvoiceDetailRouteImport.update({ - id: '/$id', - path: '/$id', - getParentRoute: () => dbDashboardInvoicesRoute, -} as any) -const dbInvoicesIndexRoute = dbInvoicesIndexRouteImport.update({ - id: '/', - path: '/', - getParentRoute: () => dbDashboardInvoicesRoute, -} as any) export interface FileRoutesByFullPath { '/': typeof indexRoute @@ -158,13 +158,6 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { - '/_layout': { - id: '/_layout' - path: '' - fullPath: '/' - preLoaderRoute: typeof layoutRouteImport - parentRoute: typeof rootRouteImport - } '/': { id: '/' path: '/' @@ -172,12 +165,12 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof indexRouteImport parentRoute: typeof rootRouteImport } - '/_layout/dashboard': { - id: '/_layout/dashboard' - path: '/dashboard' - fullPath: '/dashboard' - preLoaderRoute: typeof dbDashboardRouteImport - parentRoute: typeof layoutRoute + '/_layout': { + id: '/_layout' + path: '' + fullPath: '/' + preLoaderRoute: typeof layoutRouteImport + parentRoute: typeof rootRouteImport } '/$lang/': { id: '/$lang/' @@ -186,13 +179,20 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof pagesRouteImport parentRoute: typeof rootRouteImport } - '/_layout/hello/': { - id: '/_layout/hello/' - path: '/hello' - fullPath: '/hello/' - preLoaderRoute: typeof HelloIndexRouteImport + '/_layout/dashboard': { + id: '/_layout/dashboard' + path: '/dashboard' + fullPath: '/dashboard' + preLoaderRoute: typeof dbDashboardRouteImport parentRoute: typeof layoutRoute } + '/_layout/dashboard/': { + id: '/_layout/dashboard/' + path: '/' + fullPath: '/dashboard/' + preLoaderRoute: typeof dbDashboardIndexRouteImport + parentRoute: typeof dbDashboardRoute + } '/_layout/dashboard/invoices': { id: '/_layout/dashboard/invoices' path: '/invoices' @@ -200,12 +200,26 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof dbDashboardInvoicesRouteImport parentRoute: typeof dbDashboardRoute } - '/_layout/dashboard/': { - id: '/_layout/dashboard/' + '/_layout/hello/': { + id: '/_layout/hello/' + path: '/hello' + fullPath: '/hello/' + preLoaderRoute: typeof HelloIndexRouteImport + parentRoute: typeof layoutRoute + } + '/_layout/dashboard/invoices/': { + id: '/_layout/dashboard/invoices/' path: '/' - fullPath: '/dashboard/' - preLoaderRoute: typeof dbDashboardIndexRouteImport - parentRoute: typeof dbDashboardRoute + fullPath: '/dashboard/invoices/' + preLoaderRoute: typeof dbInvoicesIndexRouteImport + parentRoute: typeof dbDashboardInvoicesRoute + } + '/_layout/dashboard/invoices/$id': { + id: '/_layout/dashboard/invoices/$id' + path: '/$id' + fullPath: '/dashboard/invoices/$id' + preLoaderRoute: typeof dbInvoiceDetailRouteImport + parentRoute: typeof dbDashboardInvoicesRoute } '/_layout/hello/foo/': { id: '/_layout/hello/foo/' @@ -221,20 +235,6 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof HelloFooIdRouteImport parentRoute: typeof layoutRoute } - '/_layout/dashboard/invoices/$id': { - id: '/_layout/dashboard/invoices/$id' - path: '/$id' - fullPath: '/dashboard/invoices/$id' - preLoaderRoute: typeof dbInvoiceDetailRouteImport - parentRoute: typeof dbDashboardInvoicesRoute - } - '/_layout/dashboard/invoices/': { - id: '/_layout/dashboard/invoices/' - path: '/' - fullPath: '/dashboard/invoices/' - preLoaderRoute: typeof dbInvoicesIndexRouteImport - parentRoute: typeof dbDashboardInvoicesRoute - } } } diff --git a/packages/router-generator/tests/utils.test.ts b/packages/router-generator/tests/utils.test.ts index 0cdce3cfae..1d04d6b90d 100644 --- a/packages/router-generator/tests/utils.test.ts +++ b/packages/router-generator/tests/utils.test.ts @@ -6,6 +6,7 @@ import { createRoutePathSegmentMetadata, createRouteNodesByFullPath, createRouteNodesByTo, + createTokenRegex, determineInitialRoutePath, hasEscapedLeadingUnderscore, hasEscapedTrailingUnderscore, @@ -21,6 +22,7 @@ import { removeUnderscores, removeUnderscoresWithEscape, routePathToVariable, + sortRouteNodes, } from '../src/utils' import type { ImportDeclaration, RouteNode } from '../src/types' @@ -965,3 +967,85 @@ describe('RoutePrefixMap', () => { }) }) }) + +describe('sortRouteNodes', () => { + const indexTokenSegmentRegex = createTokenRegex('index', { type: 'segment' }) + + const node = (routePath: string): RouteNode => + ({ routePath }) as unknown as RouteNode + + const sortPaths = (routePaths: Array): Array => + sortRouteNodes(routePaths.map(node), indexTokenSegmentRegex).map( + (n) => n.routePath, + ) + + /** Every distinct ordering of `arr` (Heap-free recursive permutation). */ + function permutations(arr: Array): Array> { + if (arr.length <= 1) { + return [arr] + } + const result: Array> = [] + arr.forEach((item, i) => { + const rest = [...arr.slice(0, i), ...arr.slice(i + 1)] + for (const perm of permutations(rest)) { + result.push([item, ...perm]) + } + }) + return result + } + + it('orders tied siblings by routePath', () => { + // Same segment count, both non-index: they tie on every key before routePath. + const expected = ['/account/beta-features', '/account/busy-guard'] + expect( + sortPaths(['/account/busy-guard', '/account/beta-features']), + ).toEqual(expected) + expect( + sortPaths(['/account/beta-features', '/account/busy-guard']), + ).toEqual(expected) + }) + + it('applies root, segment-count and index precedence before the routePath tiebreaker', () => { + const sorted = sortPaths([ + '/posts', + '/account/busy-guard', + '/index', + '/__root', + '/account/beta-features', + '/about', + '/posts/index', + ]) + + expect(sorted).toEqual([ + '/__root', // root always first + '/index', // depth 1, index segment before non-index + '/about', // depth 1, non-index, routePath tiebreak + '/posts', // depth 1, non-index, routePath tiebreak + '/posts/index', // depth 2, index segment before non-index + '/account/beta-features', // depth 2, non-index, routePath tiebreak + '/account/busy-guard', // depth 2, non-index, routePath tiebreak + ]) + }) + + it('is deterministic for every input permutation (stable sort)', () => { + // Includes several sets that tie on all keys before routePath (the two + // `/account/*` leaves, `/about` vs `/posts`) — exactly the case that the + // former whole-object tiebreaker left in an engine- and input-order- + // dependent order. `sortRouteNodes` must map every permutation to the + // same output. + const routePaths = [ + '/__root', + '/index', + '/about', + '/posts', + '/account/beta-features', + '/account/busy-guard', + ] + + const reference = sortPaths(routePaths) + + for (const permutation of permutations(routePaths)) { + expect(sortPaths(permutation)).toEqual(reference) + } + }) +})