@@ -43,13 +43,16 @@ export class History {
4343 const buf = state . getActiveBuffer ( ) ;
4444 const serverBuffer = net . serverBuffer ( ) ;
4545 if (
46- ! state . stateBrowserDrawOpen &&
4746 ! state . activeComponent &&
47+ page < this . currentPage &&
4848 buf === serverBuffer
4949 ) {
50+ this . setPage ( 0 , true ) ;
5051 this . history . go ( ) ;
52+ return ;
5153 } else if ( page === undefined ) {
5254 this . setPage ( 0 , true ) ;
55+ return ;
5356 }
5457 this . setPage ( page ) ;
5558 } ) ;
@@ -73,33 +76,48 @@ export class History {
7376 handler && handler . enter ( ) ;
7477 }
7578
76- push ( {
77- enter,
78- leave,
79+ getUrl ( {
7980 path,
8081 query,
8182 hash,
8283 } ) {
83- // eslint-disable-next-line
84- this . log ( 'pushing.....' , ...arguments ) ;
8584 const url = new URL ( this . baseUrl ) ;
8685 if ( path ) {
8786 url . pathname = [
8887 ...url . pathname . split ( '/' ) ,
8988 ...path . split ( '/' ) ,
9089 ] . filter ( Boolean ) . join ( '/' ) ;
90+ } else {
91+ url . pathname = window . location . pathname ;
9192 }
9293 if ( query ) {
9394 Object . entries ( query ) . forEach ( ( e ) => {
9495 url . searchParams . set ( e [ 0 ] , e [ 1 ] . toString ( ) ) ;
9596 } ) ;
97+ } else if ( ! path ) {
98+ url . search = window . location . search ;
9699 }
97100 if ( hash ) {
98101 url . hash = hash ;
102+ } else if ( ! path ) {
103+ url . hash = window . location . hash ;
99104 }
100105 if ( url . pathname . charAt ( url . pathname . length - 1 ) !== '/' ) {
101106 url . pathname += '/' ;
102107 }
108+ return url ;
109+ }
110+
111+ push ( {
112+ enter,
113+ leave,
114+ path,
115+ query,
116+ hash,
117+ } ) {
118+ // eslint-disable-next-line
119+ this . log ( 'pushing.....' , ...arguments ) ;
120+ const url = this . getUrl ( { path, query, hash } ) ;
103121 if ( '' + url === '' + window . location ) {
104122 this . doReplace ( { enter, leave, url } ) ;
105123 return ;
@@ -124,24 +142,7 @@ export class History {
124142 } ) {
125143 // eslint-disable-next-line
126144 this . log ( 'replacing.....' , ...arguments ) ;
127- const url = new URL ( this . baseUrl ) ;
128- if ( path ) {
129- url . pathname = [
130- ...url . pathname . split ( '/' ) ,
131- ...path . split ( '/' ) ,
132- ] . filter ( Boolean ) . join ( '/' ) ;
133- }
134- if ( query ) {
135- Object . entries ( query ) . forEach ( ( e ) => {
136- url . searchParams . set ( e [ 0 ] , e [ 1 ] . toString ( ) ) ;
137- } ) ;
138- }
139- if ( hash ) {
140- url . hash = hash ;
141- }
142- if ( url . pathname . charAt ( url . pathname . length - 1 ) !== '/' ) {
143- url . pathname += '/' ;
144- }
145+ const url = this . getUrl ( { path, query, hash } ) ;
145146 if ( '' + url === '' + window . location ) {
146147 return ;
147148 }
0 commit comments