-
Notifications
You must be signed in to change notification settings - Fork 27.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: expected "catch all routes" are not matched in “parallel routes" (…
…#58368) <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? --> This PR fixes a bug where the expected catch-all route would not match if there were multiple "catch-all routes" under the "parallel route”. The page on the non-parallel routes path matches the catch all routes. that exist on the more detailed path. However, under parallel routes, it matches the most parent page of all the pages with catch all routes. For example, if there are files like below: ``` app/@sidebar/[...catchall]/page.tsx app/@sidebar/dashboard/[...catchall]/page.tsx ``` When accessing `/foo`, it should match `app/@sidebar/[...catchall]/page.tsx`, and this is working correctly. However, when accessing `/dashboard/foo`, it should match `app/@sidebar/dashboard/[...catchall]/page.tsx`, but `app/@sidebar/[...catchall]/page.tsx` is being matched instead. ## Repository to reproduce https://github.com/nonoakij/fix-parallel-routes-with-catch-all ## Related PR #58215 --------- Co-authored-by: Jimmy Lai <[email protected]>
- Loading branch information
1 parent
dc59d3c
commit 4fe968b
Showing
12 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...arallel-routes-and-interception/app/parallel-nested-catchall/@slot/[...catchAll]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return 'slot catchall' | ||
} |
7 changes: 7 additions & 0 deletions
7
...e/app-dir/parallel-routes-and-interception/app/parallel-nested-catchall/@slot/default.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Default() { | ||
return ( | ||
<div> | ||
<div>Default</div> | ||
</div> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
...lel-routes-and-interception/app/parallel-nested-catchall/@slot/foo/[...catchAll]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Foo() { | ||
return 'foo id catchAll' | ||
} |
3 changes: 3 additions & 0 deletions
3
.../app-dir/parallel-routes-and-interception/app/parallel-nested-catchall/@slot/foo/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Foo() { | ||
return 'foo slot' | ||
} |
3 changes: 3 additions & 0 deletions
3
...-dir/parallel-routes-and-interception/app/parallel-nested-catchall/[...catchAll]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return 'main catchall' | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-routes-and-interception/app/parallel-nested-catchall/bar/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Bar() { | ||
return 'bar' | ||
} |
3 changes: 3 additions & 0 deletions
3
...e/app-dir/parallel-routes-and-interception/app/parallel-nested-catchall/foo/[id]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return 'foo id' | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-routes-and-interception/app/parallel-nested-catchall/foo/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return 'foo' | ||
} |
24 changes: 24 additions & 0 deletions
24
test/e2e/app-dir/parallel-routes-and-interception/app/parallel-nested-catchall/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Layout({ children, slot }) { | ||
return ( | ||
<div> | ||
<div>Main content</div> | ||
<div id="main">{children}</div> | ||
<div> | ||
Slot content: | ||
<div id="slot-content">{slot}</div> | ||
</div> | ||
|
||
<div> | ||
<Link href="/parallel-nested-catchall/foo">foo</Link> | ||
</div> | ||
<div> | ||
<Link href="/parallel-nested-catchall/bar">catchall bar</Link> | ||
</div> | ||
<div> | ||
<Link href="/parallel-nested-catchall/foo/123">catchall foo id</Link> | ||
</div> | ||
</div> | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/parallel-routes-and-interception/app/parallel-nested-catchall/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Page() { | ||
return ( | ||
<div> | ||
<div>Page</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters