Commit af2d78c0 authored by Naoyuki Kanezawa's avatar Naoyuki Kanezawa Committed by Guillermo Rauch

router: register initial route (#508)

parent 87e13650
import { parse } from 'url' import { parse, format } from 'url'
import evalScript from '../eval-script' import evalScript from '../eval-script'
import shallowEquals from '../shallow-equals' import shallowEquals from '../shallow-equals'
...@@ -18,6 +18,10 @@ export default class Router { ...@@ -18,6 +18,10 @@ export default class Router {
this.onPopState = this.onPopState.bind(this) this.onPopState = this.onPopState.bind(this)
if (typeof window !== 'undefined') { 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) window.addEventListener('popstate', this.onPopState)
} }
} }
...@@ -131,7 +135,7 @@ export default class Router { ...@@ -131,7 +135,7 @@ export default class Router {
console.error(err) console.error(err)
} }
if (getURL() !== url) { if (method !== 'pushState' || getURL() !== url) {
window.history[method]({ route }, null, url) window.history[method]({ route }, null, url)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment