Skip to content

Commit

Permalink
fix(router-generator): correctly generate route tree for nested route…
Browse files Browse the repository at this point in the history
… groups (#1726)

fixes #1725
  • Loading branch information
schiller-manuel authored Jun 8, 2024
1 parent 6979e62 commit 1aa85ac
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/router-generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { Config } from './config'
let latestTask = 0
export const rootPathId = '__root'
const routeGroupPatternRegex = /\(.+\)/g
const possiblyNestedRouteGroupPatternRegex = /\([^/]+\)\/?/g

export type RouteNode = {
filePath: string
Expand Down Expand Up @@ -774,7 +775,7 @@ function replaceBackslash(s: string) {
}

function removeGroups(s: string) {
return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/')
return s.replace(possiblyNestedRouteGroupPatternRegex, '')
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* prettier-ignore-start */

/* eslint-disable */

// @ts-nocheck

// noinspection JSUnusedGlobalSymbols

// This file is auto-generated by TanStack Router

// Import Routes

import { Route as rootRoute } from './routes/__root'
import { Route as fooAsdfbarIdImport } from './routes/(foo)/asdf/(bar)/$id'

// Create/Update Routes

const fooAsdfbarIdRoute = fooAsdfbarIdImport.update({
path: '/asdf/$id',
getParentRoute: () => rootRoute,
} as any)

// Populate the FileRoutesByPath interface

declare module '@tanstack/react-router' {
interface FileRoutesByPath {
'/(foo)/asdf/(bar)/$id': {
id: '/asdf/$id'
path: '/asdf/$id'
fullPath: '/asdf/$id'
preLoaderRoute: typeof fooAsdfbarIdImport
parentRoute: typeof rootRoute
}
}
}

// Create and export the route tree

export const routeTree = rootRoute.addChildren({ fooAsdfbarIdRoute })

/* prettier-ignore-end */

/* ROUTE_MANIFEST_START
{
"routes": {
"__root__": {
"filePath": "__root.tsx",
"children": [
"/asdf/$id"
]
},
"/asdf/$id": {
"filePath": "(foo)/asdf/(bar)/$id.tsx"
}
}
}
ROUTE_MANIFEST_END */
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/(foo)/asdf/(bar)/$id')({
component: () => <div>Hello /(foo)/asdf/(bar)/$id!</div>,
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** */

0 comments on commit 1aa85ac

Please sign in to comment.