@@ -25,26 +25,30 @@ export class HashHistory extends History {
2525 const supportsScroll = supportsPushState && expectScroll
2626
2727 if ( supportsScroll ) {
28- setupScroll ( )
28+ const uninstall = setupScroll ( )
29+ this . removeEventListenerCbs . push ( uninstall )
2930 }
3031
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- } )
32+ const eventName = supportsPushState ? 'popstate' : 'hashchange'
33+ const listener = ( ) => {
34+ const current = this . current
35+ if ( ! ensureSlash ( ) ) {
36+ return
4637 }
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 )
4852 }
4953
5054 push ( location : RawLocation , onComplete ?: Function , onAbort ?: Function ) {
0 commit comments