-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option arg to changeState when onlyAHashChange (#10003)
* added option to changeState when onlyAHashChange * added integration tests * segregated tests because they caused other tests to fail Co-authored-by: JJ Kasper <[email protected]>
- Loading branch information
Showing
3 changed files
with
104 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
test/integration/client-navigation/pages/nav/hash-changes-with-state.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { Component } from 'react' | ||
import Router from 'next/router' | ||
|
||
let count = 0 | ||
|
||
export default class SelfReload extends Component { | ||
static getInitialProps({ res }) { | ||
if (res) return { count: 0 } | ||
count += 1 | ||
|
||
return { count } | ||
} | ||
|
||
handleAClick = () => { | ||
Router.push( | ||
'/nav/hash-changes-with-state', | ||
'/nav/hash-changes-with-state#', | ||
{ | ||
historyCount: (window.history.state.options.historyCount || 0) + 1, | ||
shallowHistoryCount: window.history.state.options.shallowHistoryCount, | ||
} | ||
) | ||
} | ||
|
||
handleAShallowClick = () => { | ||
Router.push( | ||
'/nav/hash-changes-with-state#', | ||
'/nav/hash-changes-with-state#', | ||
{ | ||
shallow: true, | ||
historyCount: window.history.state.options.historyCount, | ||
shallowHistoryCount: | ||
(window.history.state.options.shallowHistoryCount || 0) + 1, | ||
} | ||
) | ||
} | ||
|
||
render() { | ||
return ( | ||
<div id="hash-changes-page"> | ||
<p>COUNT: {this.props.count}</p> | ||
<a id="increment-history-count" onClick={this.handleAClick}> | ||
Increment history count | ||
</a> | ||
<div id="history-count"> | ||
HISTORY COUNT:{' '} | ||
{typeof window !== 'undefined' && | ||
window.history.state.options.historyCount} | ||
</div> | ||
<a | ||
id="increment-shallow-history-count" | ||
onClick={this.handleAShallowClick} | ||
> | ||
Increment shallow history count | ||
</a> | ||
<div id="shallow-history-count"> | ||
SHALLOW HISTORY COUNT:{' '} | ||
{typeof window !== 'undefined' && | ||
window.history.state.options.shallowHistoryCount} | ||
</div> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters