1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/test/integration/basic/pages/nav/shallow-routing.js
Arunoda Susiripala f8f3fa7dce Introducing Shallow Routing (#1357)
* Simplify route info handling.

* Add basic resolve=false support.

* Make sure to render getInitialProps always if it's the first render.

* Change resolve=false to shallow routing.

* Add test cases for shallow routing.

* Update README for shallow routing docs.

* Update docs.

* Update docs.

* Update docs.
2017-03-06 08:48:35 -08:00

45 lines
1.1 KiB
JavaScript

import { Component } from 'react'
import Link from 'next/link'
import Router from 'next/router'
let getInitialPropsRunCount = 1
const linkStyle = {
marginRight: 10
}
export default class extends Component {
static getInitialProps ({ res }) {
if (res) return { getInitialPropsRunCount: 1 }
getInitialPropsRunCount++
return { getInitialPropsRunCount }
}
increase () {
const counter = this.getCurrentCounter()
const href = `/nav/shallow-routing?counter=${counter + 1}`
Router.push(href, href, { shallow: true })
}
getCurrentCounter () {
const { url } = this.props
return url.query.counter ? parseInt(url.query.counter) : 0
}
render () {
return (
<div className='shallow-routing'>
<Link href='/nav'><a id='home-link' style={linkStyle}>Home</a></Link>
<div id='counter'>
Counter: {this.getCurrentCounter()}
</div>
<div id='get-initial-props-run-count'>
getInitialProps run count: {this.props.getInitialPropsRunCount}
</div>
<button id='increase' onClick={() => this.increase()}>Increase</button>
</div>
)
}
}