Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
add a test
  • Loading branch information
ztanner committed Apr 23, 2024
commit ec6cba1fe64b7fbb045554d9b8e87b224a340f65
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return 'intercepted'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => null
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return 'not intercepted'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function Layout({
children,
modal,
}: {
children: React.ReactNode
modal: React.ReactNode
}) {
return (
<>
<div id="children">{children}</div>
<div id="modal">{modal}</div>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default function Page() {
return (
<div>
<Link href="/foo/p/1">Foo</Link> <Link href="/foo/p/1">Foo</Link>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Default() {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function Layout(props: { children: React.ReactNode }) {
return (
<html>
<body>
<div>{props.children}</div>
</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils'

createNextDescribe(
'interception-dynamic-segment-middleware',
{
files: __dirname,
},
({ next }) => {
it('should work when interception route is paired with a dynamic segment & middleware', async () => {
const browser = await next.browser('/')

await browser.elementByCss('[href="/foo/p/1"]').click()
await check(() => browser.elementById('modal').text(), /intercepted/)
await browser.refresh()
await check(() => browser.elementById('modal').text(), '')
await check(
() => browser.elementById('children').text(),
/not intercepted/
)
})
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NextResponse, type NextRequest } from 'next/server'

export default async function middleware(request: NextRequest) {
const locale = 'en'
const { pathname } = request.nextUrl
const pathnameHasLocale =
pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
if (pathnameHasLocale) return

request.nextUrl.pathname = `/en${pathname}`
return NextResponse.rewrite(request.nextUrl)
}

export const config = {
matcher: ['/((?!api|_next|_vercel|.*\\..*).*)'],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}

module.exports = nextConfig