From d783f0eca93ad8558af2fd9fe31fa93dc57f7c71 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 24 Jun 2020 20:00:35 -0500 Subject: [PATCH] Add test case and ensure removal --- packages/next/client/index.js | 3 ++- packages/next/next-server/lib/router/router.ts | 2 +- test/integration/basepath/pages/[slug].js | 2 +- test/integration/basepath/test/index.test.js | 6 ++++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/next/client/index.js b/packages/next/client/index.js index d3a4534f9bea5..9dae7d78ae445 100644 --- a/packages/next/client/index.js +++ b/packages/next/client/index.js @@ -9,6 +9,7 @@ import { RouterContext } from '../next-server/lib/router-context' import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic' import * as envConfig from '../next-server/lib/runtime-config' import { getURL, loadGetInitialProps, ST } from '../next-server/lib/utils' +import { delBasePath } from '../next-server/lib/router/router' import initHeadManager from './head-manager' import PageLoader from './page-loader' import measureWebVitals from './performance-relayer' @@ -48,7 +49,7 @@ envConfig.setConfig({ publicRuntimeConfig: runtimeConfig || {}, }) -const asPath = getURL() +const asPath = delBasePath(getURL()) const pageLoader = new PageLoader(buildId, prefix, page) const register = ([r, f]) => pageLoader.registerPage(r, f) diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 4babcdd3d4262..063cd653f7af2 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -21,7 +21,7 @@ import getAssetPathFromRoute from './utils/get-asset-path-from-route' const basePath = (process.env.__NEXT_ROUTER_BASEPATH as string) || '' export function addBasePath(path: string): string { - return path.startsWith(basePath) ? path : `${basePath}${path}` + return `${basePath}${path}` } export function delBasePath(path: string): string { diff --git a/test/integration/basepath/pages/[slug].js b/test/integration/basepath/pages/[slug].js index 7ad5b771f38ac..53205048d0044 100644 --- a/test/integration/basepath/pages/[slug].js +++ b/test/integration/basepath/pages/[slug].js @@ -1,3 +1,3 @@ import { useRouter } from 'next/router' -export default () =>

slug: {useRouter().query.slug}

+export default () =>

slug: {useRouter().query.slug}

diff --git a/test/integration/basepath/test/index.test.js b/test/integration/basepath/test/index.test.js index d4995dd9da3e7..c9d220b74212d 100644 --- a/test/integration/basepath/test/index.test.js +++ b/test/integration/basepath/test/index.test.js @@ -116,6 +116,12 @@ const runTests = (context, dev = false) => { }) } + it('should update dynamic params after mount correctly', async () => { + const browser = await webdriver(context.appPort, '/docs/hello-dynamic') + const text = await browser.elementByCss('#slug').text() + expect(text).toContain('slug: hello-dynamic') + }) + it('should navigate to index page with getStaticProps', async () => { const browser = await webdriver(context.appPort, '/docs/hello') await browser.eval('window.beforeNavigate = "hi"')