Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
929f17e1
Unverified
Commit
929f17e1
authored
Dec 12, 2020
by
bram-l
Committed by
GitHub
Dec 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix prefetching for URLs including trailing slash (#19474)
Fixes #17813
parent
1132a8de
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
3 deletions
+44
-3
router.ts
packages/next/next-server/lib/router/router.ts
+1
-0
[slug].js
...tegration/trailing-slashes-href-resolving/pages/[slug].js
+16
-0
index.js
...ntegration/trailing-slashes-href-resolving/pages/index.js
+4
-0
index.test.js
...ration/trailing-slashes-href-resolving/test/index.test.js
+23
-3
No files found.
packages/next/next-server/lib/router/router.ts
View file @
929f17e1
...
@@ -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
}
}
...
...
test/integration/trailing-slashes-href-resolving/pages/[slug].js
View file @
929f17e1
...
@@ -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
,
}
}
test/integration/trailing-slashes-href-resolving/pages/index.js
View file @
929f17e1
...
@@ -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
/>
<
/
>
<
/
>
)
)
}
}
test/integration/trailing-slashes-href-resolving/test/index.test.js
View file @
929f17e1
/* 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'
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment