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

router: register initial route (#508)

This commit is contained in:
Naoyuki Kanezawa 2016-12-25 02:29:23 +09:00 committed by Guillermo Rauch
parent 87e136501f
commit af2d78c042

View file

@ -1,4 +1,4 @@
import { parse } from 'url'
import { parse, format } from 'url'
import evalScript from '../eval-script'
import shallowEquals from '../shallow-equals'
@ -18,6 +18,10 @@ export default class Router {
this.onPopState = this.onPopState.bind(this)
if (typeof window !== 'undefined') {
// in order for `e.state` to work on the `onpopstate` event
// we have to register the initial route upon initialization
this.replace(format({ pathname, query }), getURL())
window.addEventListener('popstate', this.onPopState)
}
}
@ -131,7 +135,7 @@ export default class Router {
console.error(err)
}
if (getURL() !== url) {
if (method !== 'pushState' || getURL() !== url) {
window.history[method]({ route }, null, url)
}