提交 0f110188 编写于 作者: N Naoyuki Kanezawa 提交者: Guillermo Rauch

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

上级 f7ee5032
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册