File tree 2 files changed +32
-3
lines changed
2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -22,13 +22,12 @@ export default class HTML5History {
22
22
}
23
23
24
24
start ( ) {
25
- let self = this
26
- this . listener = function ( e ) {
25
+ this . listener = ( e ) => {
27
26
let url = decodeURI ( location . pathname + location . search )
28
27
if ( this . root ) {
29
28
url = url . replace ( this . rootRE , '' )
30
29
}
31
- self . onChange ( url , e && e . state , location . hash )
30
+ this . onChange ( url , e && e . state , location . hash )
32
31
}
33
32
window . addEventListener ( 'popstate' , this . listener )
34
33
this . listener ( )
Original file line number Diff line number Diff line change @@ -56,6 +56,36 @@ if (!isIE9) {
56
56
}
57
57
} )
58
58
59
+ it ( 'popstate with root' , function ( ) {
60
+ var history = new History ( {
61
+ onChange : step1 ,
62
+ root : 'root/'
63
+ } )
64
+ expect ( history . root ) . toBe ( '/root' )
65
+ history . start ( )
66
+ function step1 ( ) {
67
+ history . onChange = step2
68
+ history . go ( '/' )
69
+ }
70
+ function step2 ( path ) {
71
+ expect ( location . pathname ) . toBe ( '/root/' )
72
+ expect ( path ) . toBe ( '/' )
73
+ history . onChange = step3
74
+ history . go ( '/haha' )
75
+ }
76
+ function step3 ( path ) {
77
+ expect ( location . pathname ) . toBe ( '/root/haha' )
78
+ expect ( path ) . toBe ( '/haha' )
79
+ history . onChange = step4
80
+ window . history . back ( )
81
+ }
82
+ function step4 ( path ) {
83
+ expect ( location . pathname ) . toBe ( '/root/' )
84
+ expect ( path ) . toBe ( '/' )
85
+ done ( )
86
+ }
87
+ } )
88
+
59
89
it ( 'respect <base>' , function ( done ) {
60
90
var base = document . createElement ( 'base' )
61
91
base . setAttribute ( 'href' , '/base/' )
You can’t perform that action at this time.
0 commit comments