Unverified Commit ac325dfd authored by Alexander Savelyev's avatar Alexander Savelyev Committed by GitHub

Fix intercepted segments with basepath (#60485)

### Fixing a bug

### What?
When basePath is added, intercepted routes stop working correctly.

### Why?

For them, basePath was not added at all.

### How?

Added basePath to the rewrites for intercepted routes.

Fixes #52624, #58268
parent 55917c06
......@@ -1020,7 +1020,9 @@ export default async function build(
const appPaths = Array.from(appPageKeys)
// Interception routes are modelled as beforeFiles rewrites
rewrites.beforeFiles.push(...generateInterceptionRoutesRewrites(appPaths))
rewrites.beforeFiles.push(
...generateInterceptionRoutesRewrites(appPaths, config.basePath)
)
const totalAppPagesCount = appPaths.length
......
......@@ -44,7 +44,8 @@ function voidParamsBeforeInterceptionMarker(path: string): string {
}
export function generateInterceptionRoutesRewrites(
appPaths: string[]
appPaths: string[],
basePath = ''
): Rewrite[] {
const rewrites: Rewrite[] = []
......@@ -70,8 +71,8 @@ export function generateInterceptionRoutesRewrites(
.slice(2, -3)
rewrites.push({
source: normalizedInterceptedRoute,
destination: normalizedAppPath,
source: `${basePath}${normalizedInterceptedRoute}`,
destination: `${basePath}${normalizedAppPath}`,
has: [
{
type: 'header',
......
......@@ -2270,7 +2270,10 @@ async function startWatcher(opts: SetupOpts) {
: undefined
opts.fsChecker.interceptionRoutes =
generateInterceptionRoutesRewrites(Object.keys(appPaths))?.map((item) =>
generateInterceptionRoutesRewrites(
Object.keys(appPaths),
opts.nextConfig.basePath
)?.map((item) =>
buildCustomRoute(
'before_files_rewrite',
item,
......
export default function Page() {
return <div id="nested-page-slot">Nested Page Slot</div>
}
export default function Layout(props: {
children: React.ReactNode
slot: React.ReactNode
}) {
return (
<html>
<body>
<div id="children">{props.children}</div>
{props.slot}
</body>
</html>
)
}
export default function Page() {
return <div id="nested-page-full">Nested Page Full</div>
}
import Link from 'next/link'
export default function Page() {
return (
<div>
<div id="home-page">Home page</div>
<br />
<Link id="link-to-nested" href="/nested">
To Nested
</Link>
</div>
)
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
basePath: '/base',
}
module.exports = nextConfig
import { createNextDescribe } from 'e2e-utils'
createNextDescribe(
'parallel-routes-and-interception-basepath',
{
files: __dirname,
},
({ next }) => {
it('should show parallel intercepted slot with basepath', async () => {
const browser = await next.browser('/base')
await browser.elementByCss('#link-to-nested').click()
const homePage = await browser.elementByCss('#home-page').text()
const slot = await browser.elementByCss('#nested-page-slot').text()
expect(homePage).toBe('Home page')
expect(slot).toBe('Nested Page Slot')
})
it('should show normal route via direct link with basepath when parallel intercepted slot exist', async () => {
const browser = await next.browser('/base/nested')
const nestedPageFull = await browser
.elementByCss('#nested-page-full')
.text()
expect(nestedPageFull).toBe('Nested Page Full')
})
}
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment