@@ -112,8 +112,45 @@ export async function render<SutType, WrapperType = SutType>(
112112
113113 const zone = safeInject ( NgZone ) ;
114114 const router = safeInject ( Router ) ;
115+ const _navigate = async ( elementOrPath : Element | string , basePath = '' ) : Promise < boolean > => {
116+ const href = typeof elementOrPath === 'string' ? elementOrPath : elementOrPath . getAttribute ( 'href' ) ;
117+ const [ path , params ] = ( basePath + href ) . split ( '?' ) ;
118+ const queryParams = params
119+ ? params . split ( '&' ) . reduce ( ( qp , q ) => {
120+ const [ key , value ] = q . split ( '=' ) ;
121+ const currentValue = qp [ key ] ;
122+ if ( typeof currentValue === 'undefined' ) {
123+ qp [ key ] = value ;
124+ } else if ( Array . isArray ( currentValue ) ) {
125+ qp [ key ] = [ ...currentValue , value ] ;
126+ } else {
127+ qp [ key ] = [ currentValue , value ] ;
128+ }
129+ return qp ;
130+ } , { } as Record < string , string | string [ ] > )
131+ : undefined ;
115132
116- if ( initialRoute ) await router . navigate ( [ initialRoute ] ) ;
133+ const navigateOptions : NavigationExtras | undefined = queryParams
134+ ? {
135+ queryParams,
136+ }
137+ : undefined ;
138+
139+ const doNavigate = ( ) => {
140+ return navigateOptions ? router ?. navigate ( [ path ] , navigateOptions ) : router ?. navigate ( [ path ] ) ;
141+ } ;
142+
143+ let result ;
144+
145+ if ( zone ) {
146+ await zone . run ( ( ) => ( result = doNavigate ( ) ) ) ;
147+ } else {
148+ result = doNavigate ( ) ;
149+ }
150+ return result ?? false ;
151+ } ;
152+
153+ if ( initialRoute ) await _navigate ( initialRoute ) ;
117154
118155 if ( typeof router ?. initialNavigation === 'function' ) {
119156 if ( zone ) {
@@ -167,43 +204,9 @@ export async function render<SutType, WrapperType = SutType>(
167204 } ;
168205
169206 const navigate = async ( elementOrPath : Element | string , basePath = '' ) : Promise < boolean > => {
170- const href = typeof elementOrPath === 'string' ? elementOrPath : elementOrPath . getAttribute ( 'href' ) ;
171- const [ path , params ] = ( basePath + href ) . split ( '?' ) ;
172- const queryParams = params
173- ? params . split ( '&' ) . reduce ( ( qp , q ) => {
174- const [ key , value ] = q . split ( '=' ) ;
175- const currentValue = qp [ key ] ;
176- if ( typeof currentValue === 'undefined' ) {
177- qp [ key ] = value ;
178- } else if ( Array . isArray ( currentValue ) ) {
179- qp [ key ] = [ ...currentValue , value ] ;
180- } else {
181- qp [ key ] = [ currentValue , value ] ;
182- }
183- return qp ;
184- } , { } as Record < string , string | string [ ] > )
185- : undefined ;
186-
187- const navigateOptions : NavigationExtras | undefined = queryParams
188- ? {
189- queryParams,
190- }
191- : undefined ;
192-
193- const doNavigate = ( ) => {
194- return navigateOptions ? router ?. navigate ( [ path ] , navigateOptions ) : router ?. navigate ( [ path ] ) ;
195- } ;
196-
197- let result ;
198-
199- if ( zone ) {
200- await zone . run ( ( ) => ( result = doNavigate ( ) ) ) ;
201- } else {
202- result = doNavigate ( ) ;
203- }
204-
207+ const result = await _navigate ( elementOrPath , basePath ) ;
205208 detectChanges ( ) ;
206- return result ?? false ;
209+ return result ;
207210 } ;
208211
209212 return {
0 commit comments