File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -34,11 +34,18 @@ export default class Router extends EventEmitter {
34
34
}
35
35
36
36
async onPopState ( e ) {
37
- // Older versions of safari and chrome tend to fire popstate event at the
38
- // page load.
39
- // We should not complete that event and the following check will fix it.
40
- // Fixes:
41
37
if ( ! e . state ) {
38
+ // We get state as undefined for two reasons.
39
+ // 1. With older safari (< 8) and older chrome (< 34)
40
+ // 2. When the URL changed with #
41
+ //
42
+ // In the both cases, we don't need to proceed and change the route.
43
+ // (as it's already changed)
44
+ // But we can simply replace the state with the new changes.
45
+ // Actually, for (1) we don't need to nothing. But it's hard to detect that event.
46
+ // So, doing the following for (1) does no harm.
47
+ const { pathname, query } = this
48
+ this . replace ( format ( { pathname, query } ) , getURL ( ) )
42
49
return
43
50
}
44
51
@@ -276,7 +283,8 @@ export default class Router extends EventEmitter {
276
283
}
277
284
278
285
function getURL ( ) {
279
- return window . location . pathname + ( window . location . search || '' ) + ( window . location . hash || '' )
286
+ const { href, origin } = window . location
287
+ return href . substring ( origin . length )
280
288
}
281
289
282
290
function toRoute ( path ) {
You can’t perform that action at this time.
0 commit comments