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
c6bd6ef9
Commit
c6bd6ef9
authored
Sep 27, 2017
by
Kevin Decker
Committed by
Tim Neutkens
Sep 27, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Treat navigation to empty hash as hash navigate (#2971)
# -> #foo and #foo -> # now operate in the same way.
parent
d19cc975
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
9 deletions
+24
-9
router.js
lib/router/router.js
+6
-9
hash-changes.js
test/integration/basic/pages/nav/hash-changes.js
+3
-0
client-navigation.js
test/integration/basic/test/client-navigation.js
+15
-0
No files found.
lib/router/router.js
View file @
c6bd6ef9
...
@@ -244,7 +244,7 @@ export default class Router {
...
@@ -244,7 +244,7 @@ export default class Router {
onlyAHashChange
(
as
)
{
onlyAHashChange
(
as
)
{
if
(
!
this
.
asPath
)
return
false
if
(
!
this
.
asPath
)
return
false
const
[
oldUrlNoHash
]
=
this
.
asPath
.
split
(
'#'
)
const
[
oldUrlNoHash
,
oldHash
]
=
this
.
asPath
.
split
(
'#'
)
const
[
newUrlNoHash
,
newHash
]
=
as
.
split
(
'#'
)
const
[
newUrlNoHash
,
newHash
]
=
as
.
split
(
'#'
)
// If the urls are change, there's more than a hash change
// If the urls are change, there's more than a hash change
...
@@ -252,14 +252,11 @@ export default class Router {
...
@@ -252,14 +252,11 @@ export default class Router {
return
false
return
false
}
}
// If there's no hash in the new url, we can't consider it as a hash change
// If the hash has changed, then it's a hash only change.
if
(
!
newHash
)
{
// This check is necessary to handle both the enter and
return
false
// leave hash === '' cases. The identity case falls through
}
// and is treated as a next reload.
return
oldHash
!==
newHash
// Now there's a hash in the new URL.
// We don't need to worry about the old hash.
return
true
}
}
scrollToHash
(
as
)
{
scrollToHash
(
as
)
{
...
...
test/integration/basic/pages/nav/hash-changes.js
View file @
c6bd6ef9
...
@@ -21,6 +21,9 @@ export default class SelfReload extends Component {
...
@@ -21,6 +21,9 @@ export default class SelfReload extends Component {
<
Link
href
=
'/nav/hash-changes'
>
<
Link
href
=
'/nav/hash-changes'
>
<
a
id
=
'page-url'
>
Page
URL
<
/a
>
<
a
id
=
'page-url'
>
Page
URL
<
/a
>
<
/Link
>
<
/Link
>
<
Link
href
=
'#'
>
<
a
id
=
'via-empty-hash'
>
Via
Empty
Hash
<
/a
>
<
/Link
>
<
p
>
COUNT
:
{
this
.
props
.
count
}
<
/p
>
<
p
>
COUNT
:
{
this
.
props
.
count
}
<
/p
>
<
/div
>
<
/div
>
)
)
...
...
test/integration/basic/test/client-navigation.js
View file @
c6bd6ef9
...
@@ -188,6 +188,21 @@ export default (context, render) => {
...
@@ -188,6 +188,21 @@ export default (context, render) => {
})
})
})
})
describe
(
'when hash set to empty'
,
()
=>
{
it
(
'should not run getInitialProps'
,
async
()
=>
{
const
browser
=
await
webdriver
(
context
.
appPort
,
'/nav/hash-changes'
)
const
counter
=
await
browser
.
elementByCss
(
'#via-a'
).
click
()
.
elementByCss
(
'#via-empty-hash'
).
click
()
.
elementByCss
(
'p'
).
text
()
expect
(
counter
).
toBe
(
'COUNT: 0'
)
browser
.
close
()
})
})
describe
(
'when hash changed to a different hash'
,
()
=>
{
describe
(
'when hash changed to a different hash'
,
()
=>
{
it
(
'should not run getInitialProps'
,
async
()
=>
{
it
(
'should not run getInitialProps'
,
async
()
=>
{
const
browser
=
await
webdriver
(
context
.
appPort
,
'/nav/hash-changes'
)
const
browser
=
await
webdriver
(
context
.
appPort
,
'/nav/hash-changes'
)
...
...
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