rsnext/test/integration/client-navigation/pages/nav/hash-changes-with-state.js
Richard Scotten 33b22796c7 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 <jj@jjsweb.site>
2020-01-18 20:35:12 -06:00

64 lines
1.6 KiB
JavaScript

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>
)
}
}