Unverified Commit 929f17e1 authored by bram-l's avatar bram-l Committed by GitHub

Fix prefetching for URLs including trailing slash (#19474)

Fixes  #17813 
parent 1132a8de
...@@ -1207,6 +1207,7 @@ export default class Router implements BaseRouter { ...@@ -1207,6 +1207,7 @@ export default class Router implements BaseRouter {
} }
}) })
} }
parsedHref.pathname = removePathTrailingSlash(parsedHref.pathname!)
return parsedHref return parsedHref
} }
......
...@@ -9,3 +9,19 @@ export default function Page() { ...@@ -9,3 +9,19 @@ export default function Page() {
</> </>
) )
} }
export const getStaticProps = () => {
return {
props: {
hello: 'world',
random: Math.random(),
},
}
}
export const getStaticPaths = () => {
return {
paths: ['/world', '/top-level-slug'],
fallback: false,
}
}
...@@ -27,6 +27,10 @@ export default function Index() { ...@@ -27,6 +27,10 @@ export default function Index() {
<a id="to-slug">to /top-level-slug/</a> <a id="to-slug">to /top-level-slug/</a>
</Link> </Link>
<br /> <br />
<Link as="/world" href="/[slug]">
<a id="to-slug-manual">to /world/</a>
</Link>
<br />
</> </>
) )
} }
/* eslint-env jest */ /* eslint-env jest */
import assert from 'assert'
import { join } from 'path' import { join } from 'path'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { import {
check,
findPort, findPort,
killApp, killApp,
launchApp, launchApp,
...@@ -16,7 +17,7 @@ let app ...@@ -16,7 +17,7 @@ let app
let appPort let appPort
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
const runTests = () => { const runTests = (dev) => {
it('should route to /blog/another/ correctly', async () => { it('should route to /blog/another/ correctly', async () => {
const browser = await webdriver(appPort, '/') const browser = await webdriver(appPort, '/')
await browser.elementByCss('#to-blog-another').click() await browser.elementByCss('#to-blog-another').click()
...@@ -72,6 +73,25 @@ const runTests = () => { ...@@ -72,6 +73,25 @@ const runTests = () => {
'top level slug top-level-slug' 'top level slug top-level-slug'
) )
}) })
if (!dev) {
it('should preload SSG routes correctly', async () => {
const browser = await webdriver(appPort, '/')
await check(async () => {
const hrefs = await browser.eval(`Object.keys(window.next.router.sdc)`)
hrefs.sort()
assert.deepEqual(
hrefs.map((href) =>
new URL(href).pathname.replace(/^\/_next\/data\/[^/]+/, '')
),
['/top-level-slug.json', '/world.json']
)
return 'yes'
}, 'yes')
})
}
} }
describe('href resolving trailing-slash', () => { describe('href resolving trailing-slash', () => {
...@@ -82,7 +102,7 @@ describe('href resolving trailing-slash', () => { ...@@ -82,7 +102,7 @@ describe('href resolving trailing-slash', () => {
}) })
afterAll(() => killApp(app)) afterAll(() => killApp(app))
runTests() runTests(true)
}) })
describe('production mode', () => { describe('production mode', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment