0f642dc340
### 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 |
||
---|---|---|
.. | ||
app | ||
edge-route-rewrite.test.ts | ||
middleware.ts | ||
next.config.js |