diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index 062e51422cf45..451fdedf07b37 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -644,7 +644,7 @@ export default class Server { if (!pageFound && this.dynamicRoutes) { for (const dynamicRoute of this.dynamicRoutes) { params = dynamicRoute.match(pathname) - if (params) { + if (dynamicRoute.page.startsWith('/api') && params) { page = dynamicRoute.page pageFound = true break diff --git a/test/integration/dynamic-routing/test/index.test.js b/test/integration/dynamic-routing/test/index.test.js index ec1d8ba48dd2e..7796b18f86c3d 100644 --- a/test/integration/dynamic-routing/test/index.test.js +++ b/test/integration/dynamic-routing/test/index.test.js @@ -61,6 +61,12 @@ function runTests(dev) { expect(html).toMatch(/blog post.*321.*comment.*123/i) }) + it('should not error when requesting dynamic page with /api', async () => { + const res = await fetchViaHTTP(appPort, '/api') + expect(res.status).toBe(200) + expect(await res.text()).toMatch(/this is.*?api/i) + }) + it('should render dynamic route with query', async () => { const browser = await webdriver(appPort, '/') await browser.elementByCss('#view-post-1-with-query').click()