@@ -20,17 +20,17 @@ import {
2020 */
2121export function createMemoryHistory ( base : string = '' ) : RouterHistory {
2222 let listeners : NavigationCallback [ ] = [ ]
23- let queue : HistoryLocation [ ] = [ START ]
23+ let queue : [ url : HistoryLocation , state : HistoryState ] [ ] = [ [ START , { } ] ]
2424 let position : number = 0
2525 base = normalizeBase ( base )
2626
27- function setLocation ( location : HistoryLocation ) {
27+ function setLocation ( location : HistoryLocation , state : HistoryState = { } ) {
2828 position ++
2929 if ( position !== queue . length ) {
3030 // we are in the middle, we remove everything from here in the queue
3131 queue . splice ( position )
3232 }
33- queue . push ( location )
33+ queue . push ( [ location , state ] )
3434 }
3535
3636 function triggerListeners (
@@ -51,19 +51,19 @@ export function createMemoryHistory(base: string = ''): RouterHistory {
5151 const routerHistory : RouterHistory = {
5252 // rewritten by Object.defineProperty
5353 location : START ,
54- // TODO: should be kept in queue
54+ // rewritten by Object.defineProperty
5555 state : { } ,
5656 base,
5757 createHref : createHref . bind ( null , base ) ,
5858
59- replace ( to ) {
59+ replace ( to , state ?: HistoryState ) {
6060 // remove current entry and decrement position
6161 queue . splice ( position -- , 1 )
62- setLocation ( to )
62+ setLocation ( to , state )
6363 } ,
6464
65- push ( to , data ?: HistoryState ) {
66- setLocation ( to )
65+ push ( to , state ?: HistoryState ) {
66+ setLocation ( to , state )
6767 } ,
6868
6969 listen ( callback ) {
@@ -75,7 +75,7 @@ export function createMemoryHistory(base: string = ''): RouterHistory {
7575 } ,
7676 destroy ( ) {
7777 listeners = [ ]
78- queue = [ START ]
78+ queue = [ [ START , { } ] ]
7979 position = 0
8080 } ,
8181
@@ -98,14 +98,19 @@ export function createMemoryHistory(base: string = ''): RouterHistory {
9898
9999 Object . defineProperty ( routerHistory , 'location' , {
100100 enumerable : true ,
101- get : ( ) => queue [ position ] ,
101+ get : ( ) => queue [ position ] [ 0 ] ,
102+ } )
103+
104+ Object . defineProperty ( routerHistory , 'state' , {
105+ enumerable : true ,
106+ get : ( ) => queue [ position ] [ 1 ] ,
102107 } )
103108
104109 if ( __TEST__ ) {
105110 // @ts -expect-error: only for tests
106- routerHistory . changeURL = function ( url : string ) {
111+ routerHistory . changeURL = function ( url : string , state : HistoryState = { } ) {
107112 const from = this . location
108- queue . splice ( position ++ + 1 , queue . length , url )
113+ queue . splice ( position ++ + 1 , queue . length , [ url , state ] )
109114 triggerListeners ( this . location , from , {
110115 direction : NavigationDirection . unknown ,
111116 delta : 0 ,
0 commit comments