From 7477fcd5185baf48449046111ff95e58e2a67652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A0=EA=B2=BD=ED=99=94?= Date: Thu, 15 Sep 2022 17:21:35 +0900 Subject: [PATCH 1/3] feat(test/e2e): Add router link click case in 'middleware-base-path' --- .../app/pages/dynamic-routes/[routeName].js | 11 +++++++++++ test/e2e/middleware-base-path/app/pages/index.js | 5 +++++ test/e2e/middleware-base-path/test/index.test.ts | 10 ++++++++++ 3 files changed, 26 insertions(+) create mode 100644 test/e2e/middleware-base-path/app/pages/dynamic-routes/[routeName].js diff --git a/test/e2e/middleware-base-path/app/pages/dynamic-routes/[routeName].js b/test/e2e/middleware-base-path/app/pages/dynamic-routes/[routeName].js new file mode 100644 index 000000000000000..1fe4784b683d4e2 --- /dev/null +++ b/test/e2e/middleware-base-path/app/pages/dynamic-routes/[routeName].js @@ -0,0 +1,11 @@ +import { useRouter } from 'next/router' + +export default function DynamicRoutes() { + const { query } = useRouter() + + return ( +
+

{query.routeName}

+
+ ) +} diff --git a/test/e2e/middleware-base-path/app/pages/index.js b/test/e2e/middleware-base-path/app/pages/index.js index bc2fa5dd30667ed..fdcb536dd07171b 100644 --- a/test/e2e/middleware-base-path/app/pages/index.js +++ b/test/e2e/middleware-base-path/app/pages/index.js @@ -27,6 +27,11 @@ export default function Main({ message }) { redirect me to about +
  • + + Hello World + +
  • ) diff --git a/test/e2e/middleware-base-path/test/index.test.ts b/test/e2e/middleware-base-path/test/index.test.ts index 2b8ebcb8f87834d..dffe7a1e7963eca 100644 --- a/test/e2e/middleware-base-path/test/index.test.ts +++ b/test/e2e/middleware-base-path/test/index.test.ts @@ -35,4 +35,14 @@ describe('Middleware base tests', () => { const $ = cheerio.load(html) expect($('.title').text()).toBe('About Page') }) + it('router.query must exist when Link clicked page routing', async () => { + const browser = await webdriver(next.url, '/root') + try { + await browser.elementById('go-to-hello-world-anchor').click() + const routeName = await browser.elementById('route-name').text() + expect(routeName).toMatch('hello-world') + } finally { + await browser.close() + } + }) }) From 37c3104366d04ea8a1e8bfc1fbf97b59dfb00744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A0=EA=B2=BD=ED=99=94?= Date: Thu, 15 Sep 2022 10:29:44 +0900 Subject: [PATCH 2/3] fix(next/router): Prevent query delete in routing when next.config basePath option is true --- packages/next/shared/lib/router/router.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/next/shared/lib/router/router.ts b/packages/next/shared/lib/router/router.ts index cf1180fd6766ee0..cda9125962a0719 100644 --- a/packages/next/shared/lib/router/router.ts +++ b/packages/next/shared/lib/router/router.ts @@ -1552,7 +1552,11 @@ export default class Router implements BaseRouter { query = Object.assign({}, routeInfo.query || {}, query) } - if (routeMatch && pathname !== parsed.pathname) { + const cleanedParsedPathname = hasBasePath(parsed.pathname) + ? removeBasePath(parsed.pathname) + : parsed.pathname + + if (routeMatch && pathname !== cleanedParsedPathname) { Object.keys(routeMatch).forEach((key) => { if (routeMatch && query[key] === routeMatch[key]) { delete query[key] From d6f8fbff34594b3e49ea64bc785cd8e3ad9b61b2 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 15 Sep 2022 15:15:03 -0700 Subject: [PATCH 3/3] update href --- test/e2e/middleware-base-path/app/pages/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/middleware-base-path/app/pages/index.js b/test/e2e/middleware-base-path/app/pages/index.js index fdcb536dd07171b..02138dd7460d095 100644 --- a/test/e2e/middleware-base-path/app/pages/index.js +++ b/test/e2e/middleware-base-path/app/pages/index.js @@ -28,7 +28,7 @@ export default function Main({ message }) {
  • - + Hello World