Repository: TanStack/router (ts)

Issue:
Nested route group interferes with Pathtype
### Describe the bug

When i am using nested route groups the Path type (i.e. to: "/page/component/") gets reset such that it reads from the innermost group and to the end.

Say that i have a path that is "/(auth)/org/(graphql)/$orgId/revenue" the Link will autosuggest "/$orgId/revenue" as opposed to the "/org/$orgId/revenue" as i would expect

On version: "@tanstack/react-router": "^1.35.3" i encountered an issue when i attempted to manually preloading a route with the router.preloadRoute() function. 

### Your Example Website or App

https://stackblitz.com/edit/github-isj4z7?file=src%2Froutes%2F__root.tsx

### Steps to Reproduce the Bug or Issue

1. Use the Link element on Line 30
2. Attempt to find /org/$orgId/revenue

### Expected behavior

I would expect that i could get the full path, so i can target it properly from anywhere in the app. 

### Screenshots or Videos

<img width="449" alt="Screenshot 2024-06-08 at 17 05 35" src="https://github.com/TanStack/router/assets/138299452/f7e60e10-8b13-4553-8c10-91930732cb3b">


### Platform

- OS: [MacOs]
- Browser: [Arc]
- Version: [Version 1.46.0 (50665)]


### Additional context

I do not know if this is part of the intentional design of route groups, there was limited documentation, but it seemed like a fair interpretation of the feature that nested groups would be supported. 

Pull request description:
fix(router-generator): correctly generated route tree for nested route groups
fixes #1725

Patch:
diff --git a/packages/router-generator/src/generator.ts b/packages/router-generator/src/generator.ts
index bf5ed138f..84761cf1f 100644
--- a/packages/router-generator/src/generator.ts
+++ b/packages/router-generator/src/generator.ts
@@ -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
@@ -774,7 +775,7 @@ function replaceBackslash(s: string) {
 }
 
 function removeGroups(s: string) {
-  return s.replaceAll(routeGroupPatternRegex, '').replaceAll('//', '/')
+  return s.replace(possiblyNestedRouteGroupPatternRegex, '')
 }
 
 /**


Test patch:
diff --git a/packages/router-generator/tests/generator/route-groups/routeTree.snapshot.ts b/packages/router-generator/tests/generator/route-groups/routeTree.snapshot.ts
new file mode 100644
index 000000000..b859aa928
--- /dev/null
+++ b/packages/router-generator/tests/generator/route-groups/routeTree.snapshot.ts
@@ -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 */
diff --git a/packages/router-generator/tests/generator/route-groups/routes/(foo)/asdf/(bar)/$id.tsx b/packages/router-generator/tests/generator/route-groups/routes/(foo)/asdf/(bar)/$id.tsx
new file mode 100644
index 000000000..75cbf8c35
--- /dev/null
+++ b/packages/router-generator/tests/generator/route-groups/routes/(foo)/asdf/(bar)/$id.tsx
@@ -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>,
+})
diff --git a/packages/router-generator/tests/generator/route-groups/routes/__root.tsx b/packages/router-generator/tests/generator/route-groups/routes/__root.tsx
new file mode 100644
index 000000000..ab504e42e
--- /dev/null
+++ b/packages/router-generator/tests/generator/route-groups/routes/__root.tsx
@@ -0,0 +1,1 @@
+/** */