@@ -112,8 +112,45 @@ export async function render<SutType, WrapperType = SutType>(
112
112
113
113
const zone = safeInject ( NgZone ) ;
114
114
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 ;
115
132
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 ) ;
117
154
118
155
if ( typeof router ?. initialNavigation === 'function' ) {
119
156
if ( zone ) {
@@ -167,43 +204,9 @@ export async function render<SutType, WrapperType = SutType>(
167
204
} ;
168
205
169
206
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 ) ;
205
208
detectChanges ( ) ;
206
- return result ?? false ;
209
+ return result ;
207
210
} ;
208
211
209
212
return {
0 commit comments