Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed interception on a catch-all route #72902

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function toPathToRegexpPath(path: string): string {
const paramName = capture.replace(/\W+/g, '_')

// handle catch-all segments (e.g. /foo/bar/[...baz] or /foo/bar/[[...baz]])
if (paramName.startsWith('...')) {
return `:${paramName.slice(3)}*`
if (capture.startsWith('...')) {
return `:${capture.slice(3)}*`
}
return ':' + paramName
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Link from 'next/link'
import React from 'react'

async function Page({ params }: { params: Promise<{ catchAll: string[] }> }) {
const { catchAll } = await params
return (
<div className="text-lg">
Showcase Simple Page
<Link href={`/templates/${catchAll.join('/')}`}>
templates {catchAll.join(' -> ')}
</Link>
</div>
)
}

export default Page
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function RootLayout({
children,
}: Readonly<{ children: React.ReactNode }>) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Link from 'next/link'

export default function HomePage() {
return <Link href="/templates/multi/slug">Go to test page</Link>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Link from 'next/link'
import React from 'react'

async function Page() {
return (
<div id="intercepting-page">
Showcase Intercepting Page
<Link href="/templates/single">Single</Link>
</div>
)
}

export default Page
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Link from 'next/link'
import React from 'react'

async function Page({ params }: { params: Promise<{ catchAll: string[] }> }) {
const { catchAll } = await params
return (
<div>
Simple Page
<Link href={`/showcase/${catchAll.join('/')}`}>
To Same Path <span className="opacity-70">{catchAll.join(' -> ')}</span>
</Link>
<Link href="/showcase/single">To Single Path</Link>
<Link href="/showcase/another/slug">multi-slug</Link>
</div>
)
}

export default Page
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Link from 'next/link'
import React from 'react'

function Page() {
return (
<div>
Simple Page
<Link href={'/showcase/new'}>showcase/new</Link>
</div>
)
}

export default Page
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { nextTestSetup } from 'e2e-utils'

describe('interception-routes-multiple-catchall', () => {
const { next } = nextTestSetup({
files: __dirname,
})

describe('multi-param catch-all', () => {
it('should intercept when navigating to the same path with route interception', async () => {
const browser = await next.browser('/templates/multi/slug')
await browser.elementByCss("[href='/showcase/multi/slug']").click()
await browser.waitForElementByCss('#intercepting-page')
})

it('should intercept when navigating to a single param path', async () => {
const browser = await next.browser('/templates/multi/slug')
await browser.elementByCss("[href='/showcase/single']").click()
await browser.waitForElementByCss('#intercepting-page')
})

it('should intercept when navigating to a multi-param path', async () => {
const browser = await next.browser('/templates/multi/slug')
await browser.elementByCss("[href='/showcase/another/slug']").click()
await browser.waitForElementByCss('#intercepting-page')
})
})

describe('single param catch-all', () => {
it('should intercept when navigating to a multi-param path', async () => {
const browser = await next.browser('/templates/single')
await browser.elementByCss("[href='/showcase/another/slug']").click()
await browser.waitForElementByCss('#intercepting-page')
})

it('should intercept when navigating to a single param path', async () => {
const browser = await next.browser('/templates/single')
await browser.elementByCss("[href='/showcase/single']").click()
await browser.waitForElementByCss('#intercepting-page')
})
})
})
Loading