@@ -25,26 +25,30 @@ export class HashHistory extends History {
25
25
const supportsScroll = supportsPushState && expectScroll
26
26
27
27
if ( supportsScroll ) {
28
- setupScroll ( )
28
+ const uninstall = setupScroll ( )
29
+ this . removeEventListenerCbs . push ( uninstall )
29
30
}
30
-
31
- window . addEventListener (
32
- supportsPushState ? 'popstate' : 'hashchange' ,
33
- ( ) => {
34
- const current = this . current
35
- if ( ! ensureSlash ( ) ) {
36
- return
37
- }
38
- this . transitionTo ( getHash ( ) , route => {
39
- if ( supportsScroll ) {
40
- handleScroll ( this . router , route , current , true )
41
- }
42
- if ( ! supportsPushState ) {
43
- replaceHash ( route . fullPath )
44
- }
45
- } )
31
+
32
+ const eventName = supportsPushState ? 'popstate' : 'hashchange'
33
+ const listener = ( ) => {
34
+ const current = this . current
35
+ if ( ! ensureSlash ( ) ) {
36
+ return
46
37
}
47
- )
38
+ this . transitionTo ( getHash ( ) , route => {
39
+ if ( supportsScroll ) {
40
+ handleScroll ( this . router , route , current , true )
41
+ }
42
+ if ( ! supportsPushState ) {
43
+ replaceHash ( route . fullPath )
44
+ }
45
+ } )
46
+ }
47
+ window . addEventListener ( eventName , listener )
48
+ const uninstall = ( ) => {
49
+ window . removeEventListener ( eventName , listener )
50
+ }
51
+ this . removeEventListenerCbs . push ( uninstall )
48
52
}
49
53
50
54
push ( location : RawLocation , onComplete ?: Function , onAbort ?: Function ) {
0 commit comments