Skip to content

Commit 2f12ab9

Browse files
committedJan 12, 2025
fix: routes nesting for routes w/ sub-matching ids
1 parent 9c61a5f commit 2f12ab9

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed
 

‎packages/generouted/src/core.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ test('preserved routes generation', () => {
3535
test('regular routes generation', () => {
3636
const modules = {
3737
'/src/pages/(auth)/_layout.tsx': {},
38-
'/src/pages/(auth)/login.tsx': {},
38+
'/src/pages/(auth)/login/_layout.tsx': {},
39+
'/src/pages/(auth)/login/index.tsx': {},
40+
'/src/pages/(auth)/in/_layout.tsx': {},
41+
'/src/pages/(auth)/in/index.tsx': {},
3942
'/src/pages/(auth)/register.tsx': {},
4043
'/src/pages/(external-auth)/sso.tsx': {},
4144
'/src/pages/_ignored-directory/components.tsx': {},
@@ -85,7 +88,8 @@ test('regular routes generation', () => {
8588
id: '(auth)/_layout',
8689
children: [
8790
{ path: 'register', id: '(auth)/register' },
88-
{ path: 'login', id: '(auth)/login' },
91+
{ path: 'in', id: '(auth)/in/_layout', children: [{ path: '/', id: '(auth)/in/index' }] },
92+
{ path: 'login', id: '(auth)/login/_layout', children: [{ path: '/', id: '(auth)/login/index' }] },
8993
],
9094
},
9195
{

‎packages/generouted/src/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const generateRegularRoutes = <T extends BaseRoute, M>(
5151

5252
if (root || node) {
5353
const current = root ? routes : parent.children
54-
const found = current?.find((route) => route.path === path || route.id?.replace('/_layout', '').endsWith(path))
54+
const found = current?.find((r) => r.path === path || r.id?.replace('/_layout', '').split('/').pop() === path)
5555
const props = group ? (route?.component ? { id: path, path: '/' } : { id: path }) : { path }
5656
if (found) found.children ??= []
5757
else current?.[insert]({ ...props, children: [] })

0 commit comments

Comments
 (0)
Please sign in to comment.