-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interception routes: fix interception for dynamic routes (#58198)
This PR fixes the bug in which interception routes of the form `(.)[param]` would not intercept navigations. The bug happened because we would not create a dynamic route matcher for the intercepted route, so we would never match the correct dynamic route when hitting the server, falling back to the base one. The fix consists of fixing the logic that checks for a dynamic route so that it checks the correct path when handling an interception route. There's probably a better fix here, advice welcome fixes #52533
- Loading branch information
1 parent
a6a8c84
commit 536d2db
Showing
8 changed files
with
105 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -1,6 +1,15 @@ | ||
import { | ||
extractInterceptionRouteInformation, | ||
isInterceptionRouteAppPath, | ||
} from '../../../../server/future/helpers/interception-routes' | ||
|
||
// Identify /[param]/ in route string | ||
const TEST_ROUTE = /\/\[[^/]+?\](?=\/|$)/ | ||
|
||
export function isDynamicRoute(route: string): boolean { | ||
if (isInterceptionRouteAppPath(route)) { | ||
route = extractInterceptionRouteInformation(route).interceptedRoute | ||
} | ||
|
||
return TEST_ROUTE.test(route) | ||
} |
8 changes: 8 additions & 0 deletions
8
...app-dir/parallel-routes-and-interception/app/intercepting-siblings/@modal/(.)[id]/page.js
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,8 @@ | ||
export default function Page({ params: { id } }) { | ||
return ( | ||
<div> | ||
<h2>intercepting-siblings</h2> | ||
<p id="intercepted-sibling">{id}</p> | ||
</div> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
.../e2e/app-dir/parallel-routes-and-interception/app/intercepting-siblings/@modal/default.js
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 Default() { | ||
return <div>default</div> | ||
} |
8 changes: 8 additions & 0 deletions
8
test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-siblings/[id]/page.js
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,8 @@ | ||
export default function Page({ params: { id } }) { | ||
return ( | ||
<div> | ||
<h2>main slot</h2> | ||
<p id="main-slot">{id}</p> | ||
</div> | ||
) | ||
} |
29 changes: 29 additions & 0 deletions
29
test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-siblings/layout.js
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,29 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Layout({ children, modal }) { | ||
return ( | ||
<div> | ||
<h1>intercepting-siblings</h1> | ||
<div style={{ border: '1px solid black', padding: '1rem' }}> | ||
{children} | ||
</div> | ||
<hr /> | ||
<div style={{ border: '1px solid black', padding: '1rem' }}>{modal}</div> | ||
<h1>links</h1> | ||
<ul> | ||
<li> | ||
<Link href="/intercepting-siblings">/intercepting-siblings</Link> | ||
</li> | ||
<li> | ||
<Link href="/intercepting-siblings/1">/intercepting-siblings/1</Link> | ||
</li> | ||
<li> | ||
<Link href="/intercepting-siblings/2">/intercepting-siblings/2</Link> | ||
</li> | ||
<li> | ||
<Link href="/intercepting-siblings/3">/intercepting-siblings/3</Link> | ||
</li> | ||
</ul> | ||
</div> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-siblings/page.js
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 <div>main page</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