Skip to content

Commit

Permalink
fix(react-router): remove groups when using createLazyFileRoute (#2220
Browse files Browse the repository at this point in the history
)

fixes #2219
  • Loading branch information
schiller-manuel authored Aug 29, 2024
1 parent c6a80d6 commit bac62c5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/react-router/src/fileRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,16 @@ export function createLazyRoute<
}
}

const routeGroupPatternRegex = /\(.+\)/g

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

export function createLazyFileRoute<
TFilePath extends keyof FileRoutesByPath,
TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],
>(id: TFilePath) {
return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts })
return (opts: LazyRouteOptions) =>
new LazyRoute<TRoute>({ id: removeGroups(id), ...opts })
}

0 comments on commit bac62c5

Please sign in to comment.