Unverified Commit 5160aa72 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Fix route.js trailingSlash handling (#46185)

<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:
-->

Fixes NEXT-598

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 1ccb9afe
...@@ -6,6 +6,7 @@ import { AppRouteRouteHandler } from '../../../../server/future/route-handlers/a ...@@ -6,6 +6,7 @@ import { AppRouteRouteHandler } from '../../../../server/future/route-handlers/a
import { RouteKind } from '../../../../server/future/route-kind' import { RouteKind } from '../../../../server/future/route-kind'
import { AppRouteRouteMatcher } from '../../../../server/future/route-matchers/app-route-route-matcher' import { AppRouteRouteMatcher } from '../../../../server/future/route-matchers/app-route-route-matcher'
import { normalizeAppPath } from '../../../../shared/lib/router/utils/app-paths' import { normalizeAppPath } from '../../../../shared/lib/router/utils/app-paths'
import { removeTrailingSlash } from '../../../../shared/lib/router/utils/remove-trailing-slash'
export function getHandle({ page, mod }: any) { export function getHandle({ page, mod }: any) {
const appRouteRouteHandler = new AppRouteRouteHandler() const appRouteRouteHandler = new AppRouteRouteHandler()
...@@ -20,7 +21,9 @@ export function getHandle({ page, mod }: any) { ...@@ -20,7 +21,9 @@ export function getHandle({ page, mod }: any) {
return async function handle(request: Request) { return async function handle(request: Request) {
const extendedReq = new WebNextRequest(request) const extendedReq = new WebNextRequest(request)
const extendedRes = new WebNextResponse() const extendedRes = new WebNextResponse()
const match = appRouteRouteMatcher.match(new URL(request.url).pathname)! const match = appRouteRouteMatcher.match(
removeTrailingSlash(new URL(request.url).pathname)
)!
const response = await appRouteRouteHandler.execute( const response = await appRouteRouteHandler.execute(
match, match,
mod, mod,
......
import { createNextDescribe } from 'e2e-utils'
createNextDescribe(
'app-routes-trailing-slash',
{
files: __dirname,
},
({ next }) => {
it('should work with node runtime', async () => {
const res = await next.fetch('/api/')
const html = await res.text()
expect(html).toContain('Hello World')
})
it('should work edge node runtime', async () => {
const res = await next.fetch('/api/edge/')
const html = await res.text()
expect(html).toContain('Hello World')
})
}
)
export const runtime = 'edge'
export async function GET() {
return new Response('Hello World')
}
export async function GET() {
return new Response('Hello World')
}
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>hello world</p>
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
trailingSlash: true,
experimental: { appDir: true },
}
module.exports = nextConfig
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