Skip to content

Commit

Permalink
Fix SSG data request failing with trailing slash (#10140)
Browse files Browse the repository at this point in the history
* Fix SSG data request failing with trailing slash

* Update to re-use toRoute method
  • Loading branch information
ijjk authored and Timer committed Jan 17, 2020
1 parent ee07612 commit 51420c7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/next/next-server/lib/router/router.ts
Expand Up @@ -666,7 +666,7 @@ export default class Router implements BaseRouter {

_getStaticData = (asPath: string, _cachedData?: object): Promise<object> => {
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])
Expand Down
2 changes: 1 addition & 1 deletion test/integration/prerender/pages/index.js
Expand Up @@ -14,7 +14,7 @@ const Page = ({ world, time }) => {
<>
<p>hello {world}</p>
<span>time: {time}</span>
<Link href="/another">
<Link href="/another?hello=world" as="/another/?hello=world">
<a id="another">to another</a>
</Link>
<br />
Expand Down
2 changes: 2 additions & 0 deletions test/integration/prerender/test/index.test.js
Expand Up @@ -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()
Expand Down

0 comments on commit 51420c7

Please sign in to comment.