1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

fix getInitialProps called on client on first load (#572)

This commit is contained in:
Naoyuki Kanezawa 2016-12-31 04:55:00 +09:00 committed by Guillermo Rauch
parent f7ee50323d
commit 0f11018819

View file

@ -32,6 +32,9 @@ export default class Router {
const as = getURL()
const { url = as } = e.state || {}
const { pathname, query } = parse(url, true)
if (!this.urlIsNew(pathname, query)) return
const route = toRoute(pathname)
Promise.resolve()
@ -113,6 +116,12 @@ export default class Router {
async change (method, url, as) {
const { pathname, query } = parse(url, true)
if (!this.urlIsNew(pathname, query)) {
changeState()
return true
}
const route = toRoute(pathname)
this.abortComponentLoad()
@ -135,9 +144,7 @@ export default class Router {
console.error(err)
}
if (method !== 'pushState' || getURL() !== as) {
window.history[method]({ url }, null, as)
}
changeState()
this.route = route
this.set(pathname, query, { ...data, props })
@ -145,14 +152,18 @@ export default class Router {
if (_err) throw _err
return true
function changeState () {
if (method !== 'pushState' || getURL() !== as) {
window.history[method]({ url }, null, as)
}
}
}
set (pathname, query, data) {
if (this.urlIsNew(pathname, query)) {
this.pathname = pathname
this.query = query
this.notify(data)
}
this.pathname = pathname
this.query = query
this.notify(data)
}
urlIsNew (pathname, query) {