@@ -379,48 +379,50 @@ export function historySyncPlugin<
379379 onInit ( { actions : { getStack, dispatchEvent, push, stepPush } } ) {
380380 const stack = getStack ( ) ;
381381
382- for ( const activity of stack . activities ) {
383- if (
384- activity . transitionState === "enter-active" ||
385- activity . transitionState === "enter-done"
386- ) {
387- const match = activityRoutes . find (
388- ( r ) => r . activityName === activity . name ,
389- ) ! ;
390- const template = makeTemplate ( match , options . urlPatternOptions ) ;
391-
392- if ( activity . isRoot ) {
393- replaceState ( {
394- history,
395- pathname : template . fill ( activity . params ) ,
396- state : {
397- activity : activity ,
398- } ,
399- useHash : options . useHash ,
400- } ) ;
401- } else {
402- pushState ( {
403- history,
404- pathname : template . fill ( activity . params ) ,
405- state : {
406- activity : activity ,
407- } ,
408- useHash : options . useHash ,
409- } ) ;
410- }
382+ if ( parseState ( history . location . state ) === null ) {
383+ for ( const activity of stack . activities ) {
384+ if (
385+ activity . transitionState === "enter-active" ||
386+ activity . transitionState === "enter-done"
387+ ) {
388+ const match = activityRoutes . find (
389+ ( r ) => r . activityName === activity . name ,
390+ ) ! ;
391+ const template = makeTemplate ( match , options . urlPatternOptions ) ;
411392
412- for ( const step of activity . steps ) {
413- if ( ! step . exitedBy && step . enteredBy . name !== "Pushed" ) {
393+ if ( activity . isRoot ) {
394+ replaceState ( {
395+ history,
396+ pathname : template . fill ( activity . params ) ,
397+ state : {
398+ activity : activity ,
399+ } ,
400+ useHash : options . useHash ,
401+ } ) ;
402+ } else {
414403 pushState ( {
415404 history,
416- pathname : template . fill ( step . params ) ,
405+ pathname : template . fill ( activity . params ) ,
417406 state : {
418407 activity : activity ,
419- step : step ,
420408 } ,
421409 useHash : options . useHash ,
422410 } ) ;
423411 }
412+
413+ for ( const step of activity . steps ) {
414+ if ( ! step . exitedBy && step . enteredBy . name !== "Pushed" ) {
415+ pushState ( {
416+ history,
417+ pathname : template . fill ( step . params ) ,
418+ state : {
419+ activity : activity ,
420+ step : step ,
421+ } ,
422+ useHash : options . useHash ,
423+ } ) ;
424+ }
425+ }
424426 }
425427 }
426428 }
0 commit comments