@@ -33,10 +33,6 @@ export class MobxRouter implements IMobxRouter {
3333 config . location ?? new MobxLocation ( this . history , config . abortSignal ) ;
3434 this . queryParams =
3535 config . queryParams ?? new QueryParams ( this . location , this . history ) ;
36-
37- if ( ! this . location . hash && this . type === 'hash' ) {
38- this . hashNavigate ( '/' ) ;
39- }
4036 }
4137
4238 createPath ( to : RouterToConfig ) : RouterPath {
@@ -81,9 +77,9 @@ export class MobxRouter implements IMobxRouter {
8177 const state = options ?. state ?? null ;
8278
8379 this . wrapInViewTransition ( ( ) => {
84- this . location . hash = path . hash ;
80+ this . location . hash = `# ${ path . pathname || '/' } ` ;
8581 this . history . replaceState ( state , '' , url ) ;
86- } ) ;
82+ } , options ?. useStartViewTransition ) ;
8783 }
8884
8985 protected browserNavigate (
@@ -100,13 +96,21 @@ export class MobxRouter implements IMobxRouter {
10096 } else {
10197 this . history . pushState ( state , '' , url ) ;
10298 }
103- } ) ;
99+ } , options ?. useStartViewTransition ) ;
104100 }
105101
106102 protected lastViewTransition ?: ViewTransition ;
107103
108- protected wrapInViewTransition ( action : ( ) => void ) {
109- if ( this . config . useStartViewTransition && document . startViewTransition ) {
104+ protected wrapInViewTransition (
105+ action : ( ) => void ,
106+ useStartViewTransition ?: boolean ,
107+ ) {
108+ if (
109+ ( useStartViewTransition ||
110+ ( useStartViewTransition == null &&
111+ this . config . useStartViewTransition ) ) &&
112+ document . startViewTransition
113+ ) {
110114 if ( this . lastViewTransition ) {
111115 this . lastViewTransition . skipTransition ( ) ;
112116 }
@@ -122,38 +126,10 @@ export class MobxRouter implements IMobxRouter {
122126 }
123127
124128 navigate ( to : RouterToConfig , options ?: RouterNavigateParams ) : void {
125- const path = this . createPath ( to ) ;
126- const url = this . createUrl ( path , this . type ) ;
127- const state = options ?. state ?? null ;
128- const useReplace =
129- options ?. replace || ( options ?. replace == null && this . type === 'hash' ) ;
130-
131- const navigateAction = ( ) => {
132- if ( this . type === 'hash' ) {
133- this . location . hash = path . hash ;
134- }
135-
136- if ( useReplace ) {
137- this . history . replaceState ( state , '' , url ) ;
138- } else {
139- this . history . pushState ( state , '' , url ) ;
140- }
141- } ;
142-
143- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
144- // @ts -ignore
145- if ( this . config . useStartViewTransition && document . startViewTransition ) {
146- if ( this . lastViewTransition ) {
147- this . lastViewTransition . skipTransition ( ) ;
148- }
149- this . lastViewTransition = document . startViewTransition ( ( ) => {
150- startTransition ( navigateAction ) ;
151- } ) ;
152- this . lastViewTransition . finished . finally ( ( ) => {
153- delete this . lastViewTransition ;
154- } ) ;
129+ if ( this . type === 'hash' ) {
130+ this . hashNavigate ( to , options ) ;
155131 } else {
156- navigateAction ( ) ;
132+ this . browserNavigate ( to , options ) ;
157133 }
158134 }
159135
0 commit comments