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 {
3434 }
3535
3636 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:
4137 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 ( ) )
4249 return
4350 }
4451
@@ -276,7 +283,8 @@ export default class Router extends EventEmitter {
276283}
277284
278285function getURL ( ) {
279- return window . location . pathname + ( window . location . search || '' ) + ( window . location . hash || '' )
286+ const { href, origin } = window . location
287+ return href . substring ( origin . length )
280288}
281289
282290function toRoute ( path ) {
You can’t perform that action at this time.
0 commit comments