Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/router-generator/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ export class RoutePrefixMap {
for (const route of routes) {
if (!route.routePath || route.routePath === `/${rootPathId}`) continue

// Skip route pieces (lazy, loader, component, etc.) - they are merged with main routes
// and should not be valid parent candidates
if (
route._fsRouteType === 'lazy' ||
route._fsRouteType === 'loader' ||
route._fsRouteType === 'component' ||
route._fsRouteType === 'pendingComponent' ||
route._fsRouteType === 'errorComponent' ||
route._fsRouteType === 'notFoundComponent'
) {
continue
}

// Index by exact path for direct lookups
this.prefixToRoute.set(route.routePath, route)

Expand Down
104 changes: 104 additions & 0 deletions packages/router-generator/tests/generator/lazy/routeTree.snapshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* eslint-disable */

// @ts-nocheck

// noinspection JSUnusedGlobalSymbols

// This file was automatically generated by TanStack Router.
// You should NOT make any changes in this file as it will be overwritten.
// 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 PostsIndexRouteImport } from './routes/posts.index'
import { Route as PostsPostIdRouteImport } from './routes/posts.$postId'

const PostsRouteRoute = PostsRouteRouteImport.update({
id: '/posts',
path: '/posts',
getParentRoute: () => rootRouteImport,
} as any).lazy(() => import('./routes/posts.route.lazy').then((d) => d.Route))
const PostsIndexRoute = PostsIndexRouteImport.update({
id: '/',
path: '/',
getParentRoute: () => PostsRouteRoute,
} as any)
const PostsPostIdRoute = PostsPostIdRouteImport.update({
id: '/$postId',
path: '/$postId',
getParentRoute: () => PostsRouteRoute,
} as any)

export interface FileRoutesByFullPath {
'/posts': typeof PostsRouteRouteWithChildren
'/posts/$postId': typeof PostsPostIdRoute
'/posts/': typeof PostsIndexRoute
}
export interface FileRoutesByTo {
'/posts/$postId': typeof PostsPostIdRoute
'/posts': typeof PostsIndexRoute
}
export interface FileRoutesById {
__root__: typeof rootRouteImport
'/posts': typeof PostsRouteRouteWithChildren
'/posts/$postId': typeof PostsPostIdRoute
'/posts/': typeof PostsIndexRoute
}
export interface FileRouteTypes {
fileRoutesByFullPath: FileRoutesByFullPath
fullPaths: '/posts' | '/posts/$postId' | '/posts/'
fileRoutesByTo: FileRoutesByTo
to: '/posts/$postId' | '/posts'
id: '__root__' | '/posts' | '/posts/$postId' | '/posts/'
fileRoutesById: FileRoutesById
}
export interface RootRouteChildren {
PostsRouteRoute: typeof PostsRouteRouteWithChildren
}

declare module '@tanstack/react-router' {
interface FileRoutesByPath {
'/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
}
'/posts/$postId': {
id: '/posts/$postId'
path: '/$postId'
fullPath: '/posts/$postId'
preLoaderRoute: typeof PostsPostIdRouteImport
parentRoute: typeof PostsRouteRoute
}
}
}

interface PostsRouteRouteChildren {
PostsPostIdRoute: typeof PostsPostIdRoute
PostsIndexRoute: typeof PostsIndexRoute
}

const PostsRouteRouteChildren: PostsRouteRouteChildren = {
PostsPostIdRoute: PostsPostIdRoute,
PostsIndexRoute: PostsIndexRoute,
}

const PostsRouteRouteWithChildren = PostsRouteRoute._addFileChildren(
PostsRouteRouteChildren,
)

const rootRouteChildren: RootRouteChildren = {
PostsRouteRoute: PostsRouteRouteWithChildren,
}
export const routeTree = rootRouteImport
._addFileChildren(rootRouteChildren)
._addFileTypes<FileRouteTypes>()
15 changes: 15 additions & 0 deletions packages/router-generator/tests/generator/lazy/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react'
import { Outlet, createRootRoute } from '@tanstack/react-router'

export const Route = createRootRoute({
component: RootComponent,
})

function RootComponent() {
return (
<React.Fragment>
<div>Hello "__root"!</div>
<Outlet />
</React.Fragment>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/posts/$postId')({
component: RouteComponent,
})

function RouteComponent() {
return <div>Hello "/posts/$postId"!</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/posts/')({
component: RouteComponent,
})

function RouteComponent() {
return <div>Hello "/posts/"!</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createLazyFileRoute } from '@tanstack/react-router'

export const Route = createLazyFileRoute('/posts')({
component: RouteComponent,
})

function RouteComponent() {
return <div>Hello "/posts"!</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/posts')({
component: RouteComponent,
})

function RouteComponent() {
return <div>Hello "/posts"!</div>
}
Loading