Commit 5b2854dc authored by Arunoda Susiripala's avatar Arunoda Susiripala Committed by Naoyuki Kanezawa

Properly handle hash URL changes. (#996)

* Properly handle hash URL changes.

* Make sure we replace origin correctly.

* Get rid of RegExp for getUrl().
parent a8731d06
...@@ -34,11 +34,18 @@ export default class Router extends EventEmitter { ...@@ -34,11 +34,18 @@ export default class Router extends EventEmitter {
} }
async onPopState (e) { async onPopState (e) {
// Older versions of safari and chrome tend to fire popstate event at the
// page load.
// We should not complete that event and the following check will fix it.
// Fixes:
if (!e.state) { if (!e.state) {
// We get state as undefined for two reasons.
// 1. With older safari (< 8) and older chrome (< 34)
// 2. When the URL changed with #
//
// In the both cases, we don't need to proceed and change the route.
// (as it's already changed)
// But we can simply replace the state with the new changes.
// Actually, for (1) we don't need to nothing. But it's hard to detect that event.
// So, doing the following for (1) does no harm.
const { pathname, query } = this
this.replace(format({ pathname, query }), getURL())
return return
} }
...@@ -276,7 +283,8 @@ export default class Router extends EventEmitter { ...@@ -276,7 +283,8 @@ export default class Router extends EventEmitter {
} }
function getURL () { function getURL () {
return window.location.pathname + (window.location.search || '') + (window.location.hash || '') const { href, origin } = window.location
return href.substring(origin.length)
} }
function toRoute (path) { function toRoute (path) {
......
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