mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
### What? Rewrites to an edge route currently throw an invariant rather than properly serving up the page that is rewritten to. ### Why? The `NextRequest` object that is provided to the edge route handler contains pathname information only for the "origin" request (e.g., when visiting `/one/example` which rewrites to `/two/example`, the pathname is still `/one/example`. This hits an invariant since the route matcher is unable to find `/one/example` since it does not exist. ### How? This updates the module wrapper to grab the pathname from the route definition rather than the request object. For dynamic segments, we extract them from `request.nextUrl` since we know that even if `nextUrl` is referencing the origin path, the parameters it has are relevant for the rewrite. This adds the `getUtils` utility that's also used in base-server to handle the URL normalization, which also provides an interface for normalizing dynamic params from a `ParsedUrlQuery`. Closes NEXT-1724 Fixes #48295
22 lines
594 B
TypeScript
22 lines
594 B
TypeScript
import { createNextDescribe } from 'e2e-utils'
|
|
|
|
createNextDescribe(
|
|
'edge-route-rewrite',
|
|
{
|
|
files: __dirname,
|
|
},
|
|
({ next }) => {
|
|
it('it should support a rewrite to an edge route', async () => {
|
|
const result = await next.render('/one/example')
|
|
expect(result).toContain('Hello from /app/two/example/route.ts')
|
|
})
|
|
|
|
it('it should support a rewrite to a dynamic edge route', async () => {
|
|
const result = await next.render('/dynamic-test/foo')
|
|
expect(result).toContain(
|
|
'Hello from /app/dynamic/[slug]/route.ts. Slug: foo'
|
|
)
|
|
})
|
|
}
|
|
)
|