File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 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 {
2222 }
2323
2424 start ( ) {
25- let self = this
26- this . listener = function ( e ) {
25+ this . listener = ( e ) => {
2726 let url = decodeURI ( location . pathname + location . search )
2827 if ( this . root ) {
2928 url = url . replace ( this . rootRE , '' )
3029 }
31- self . onChange ( url , e && e . state , location . hash )
30+ this . onChange ( url , e && e . state , location . hash )
3231 }
3332 window . addEventListener ( 'popstate' , this . listener )
3433 this . listener ( )
Original file line number Diff line number Diff line change @@ -56,6 +56,36 @@ if (!isIE9) {
5656 }
5757 } )
5858
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+
5989 it ( 'respect <base>' , function ( done ) {
6090 var base = document . createElement ( 'base' )
6191 base . setAttribute ( 'href' , '/base/' )
You can’t perform that action at this time.
0 commit comments