From 51420c724138927e9f065a74cc272fcda993143d Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 17 Jan 2020 10:54:00 -0600 Subject: [PATCH] Fix SSG data request failing with trailing slash (#10140) * Fix SSG data request failing with trailing slash * Update to re-use toRoute method --- packages/next/next-server/lib/router/router.ts | 2 +- test/integration/prerender/pages/index.js | 2 +- test/integration/prerender/test/index.test.js | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 508b941e191bbad..0abdad552fbde27 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -666,7 +666,7 @@ export default class Router implements BaseRouter { _getStaticData = (asPath: string, _cachedData?: object): Promise => { let pathname = parse(asPath).pathname - pathname = !pathname || pathname === '/' ? '/index' : pathname + pathname = toRoute(!pathname || pathname === '/' ? '/index' : pathname) return process.env.NODE_ENV === 'production' && (_cachedData = this.sdc[pathname]) diff --git a/test/integration/prerender/pages/index.js b/test/integration/prerender/pages/index.js index 295502017aeb649..a81149f600a59f5 100644 --- a/test/integration/prerender/pages/index.js +++ b/test/integration/prerender/pages/index.js @@ -14,7 +14,7 @@ const Page = ({ world, time }) => { <>

hello {world}

time: {time} - + to another
diff --git a/test/integration/prerender/test/index.test.js b/test/integration/prerender/test/index.test.js index e71be48a58827fe..2b8f4109518075a 100644 --- a/test/integration/prerender/test/index.test.js +++ b/test/integration/prerender/test/index.test.js @@ -134,9 +134,11 @@ const navigateTest = (dev = false) => { // go to /another async function goFromHomeToAnother() { + await browser.eval('window.beforeAnother = true') await browser.elementByCss('#another').click() await browser.waitForElementByCss('#home') text = await browser.elementByCss('p').text() + expect(await browser.eval('window.beforeAnother')).toBe(true) expect(text).toMatch(/hello.*?world/) } await goFromHomeToAnother()