20
20
import java .util .Optional ;
21
21
22
22
import com .vaadin .flow .component .UI ;
23
+ import com .vaadin .flow .internal .JacksonUtils ;
23
24
import com .vaadin .flow .router .internal .DefaultRouteResolver ;
24
25
import com .vaadin .flow .router .internal .ErrorStateRenderer ;
25
26
import com .vaadin .flow .router .internal .ErrorTargetEntry ;
34
35
import com .vaadin .flow .server .VaadinService ;
35
36
import com .vaadin .flow .server .VaadinSession ;
36
37
38
+ import com .fasterxml .jackson .databind .node .BaseJsonNode ;
37
39
import org .slf4j .LoggerFactory ;
38
40
39
41
import elemental .json .JsonValue ;
@@ -76,8 +78,10 @@ public Router(RouteRegistry registry) {
76
78
* the location object of the route
77
79
*/
78
80
public void initializeUI (UI ui , Location location ) {
79
- ui .getPage ().getHistory ().setHistoryStateChangeHandler (e -> navigate (ui ,
80
- e .getLocation (), e .getTrigger (), e .getState ().orElse (null )));
81
+ ui .getPage ().getHistory ()
82
+ .setHistoryStateChangeHandler (e -> navigate (ui , e .getLocation (),
83
+ e .getTrigger (),
84
+ JacksonUtils .mapElemental (e .getState ().orElse (null ))));
81
85
82
86
int statusCode = navigate (ui , location , NavigationTrigger .PAGE_LOAD );
83
87
@@ -164,7 +168,7 @@ public Optional<NavigationState> resolveRouteNotFoundNavigationTarget() {
164
168
* @see UI#navigate(String, QueryParameters)
165
169
*/
166
170
public int navigate (UI ui , Location location , NavigationTrigger trigger ) {
167
- return navigate (ui , location , trigger , null );
171
+ return navigate (ui , location , trigger , ( BaseJsonNode ) null );
168
172
}
169
173
170
174
/**
@@ -189,7 +193,7 @@ public int navigate(UI ui, Location location, NavigationTrigger trigger) {
189
193
* @see UI#navigate(String, QueryParameters)
190
194
*/
191
195
public int navigate (UI ui , Location location , NavigationTrigger trigger ,
192
- JsonValue state ) {
196
+ BaseJsonNode state ) {
193
197
return navigate (ui , location , trigger , state , false , false );
194
198
}
195
199
@@ -222,7 +226,7 @@ public int navigate(UI ui, Location location, NavigationTrigger trigger,
222
226
* @see UI#navigate(String, QueryParameters)
223
227
*/
224
228
public int navigate (UI ui , Location location , NavigationTrigger trigger ,
225
- JsonValue state , boolean forceInstantiation ,
229
+ BaseJsonNode state , boolean forceInstantiation ,
226
230
boolean recreateLayoutChain ) {
227
231
assert ui != null ;
228
232
assert location != null ;
@@ -243,6 +247,69 @@ public int navigate(UI ui, Location location, NavigationTrigger trigger,
243
247
return HttpStatusCode .NOT_MODIFIED .getCode ();
244
248
}
245
249
250
+ /**
251
+ * Navigates the given UI to the given location. For internal use only.
252
+ * <p>
253
+ * This method pushes to the browser history if the <code>trigger</code> is
254
+ * {@link NavigationTrigger#ROUTER_LINK} or
255
+ * {@link NavigationTrigger#UI_NAVIGATE}.
256
+ *
257
+ * @param ui
258
+ * the UI to update, not <code>null</code>
259
+ * @param location
260
+ * the location to navigate to, not <code>null</code>
261
+ * @param trigger
262
+ * the type of user action that triggered this navigation, not
263
+ * <code>null</code>
264
+ * @param state
265
+ * includes navigation state info including for example the
266
+ * scroll position and the complete href of the RouterLink
267
+ * @return the HTTP status code resulting from the navigation
268
+ * @see UI#navigate(String)
269
+ * @see UI#navigate(String, QueryParameters)
270
+ */
271
+ @ Deprecated
272
+ public int navigate (UI ui , Location location , NavigationTrigger trigger ,
273
+ JsonValue state ) {
274
+ return navigate (ui , location , trigger , state , false , false );
275
+ }
276
+
277
+ /**
278
+ * Navigates the given UI to the given location. For internal use only.
279
+ * <p>
280
+ * This method pushes to the browser history if the <code>trigger</code> is
281
+ * {@link NavigationTrigger#ROUTER_LINK} or
282
+ * {@link NavigationTrigger#UI_NAVIGATE}.
283
+ *
284
+ * @param ui
285
+ * the UI to update, not <code>null</code>
286
+ * @param location
287
+ * the location to navigate to, not <code>null</code>
288
+ * @param trigger
289
+ * the type of user action that triggered this navigation, not
290
+ * <code>null</code>
291
+ * @param state
292
+ * includes navigation state info including for example the
293
+ * scroll position and the complete href of the RouterLink
294
+ * @param forceInstantiation
295
+ * if set to {@code true}, the navigation target will always be
296
+ * instantiated
297
+ * @param recreateLayoutChain
298
+ * if set to {@code true}, the complete layout chain up to the
299
+ * navigation target will be re-instantiated. Requires
300
+ * {@code forceInstantiation} to be true to have an effect.
301
+ * @return the HTTP status code resulting from the navigation
302
+ * @see UI#navigate(String)
303
+ * @see UI#navigate(String, QueryParameters)
304
+ */
305
+ @ Deprecated
306
+ public int navigate (UI ui , Location location , NavigationTrigger trigger ,
307
+ JsonValue state , boolean forceInstantiation ,
308
+ boolean recreateLayoutChain ) {
309
+ return navigate (ui , location , trigger , JacksonUtils .mapElemental (state ),
310
+ forceInstantiation , recreateLayoutChain );
311
+ }
312
+
246
313
private boolean handleNavigationForLocation (UI ui , Location location ) {
247
314
if (ui .getInternals ().hasLastHandledLocation ()) {
248
315
return !location .getPathWithQueryParameters ()
@@ -253,7 +320,7 @@ private boolean handleNavigationForLocation(UI ui, Location location) {
253
320
}
254
321
255
322
private int handleNavigation (UI ui , Location location ,
256
- NavigationTrigger trigger , JsonValue state ,
323
+ NavigationTrigger trigger , BaseJsonNode state ,
257
324
boolean forceInstantiation , boolean recreateLayoutChain ) {
258
325
NavigationState newState = getRouteResolver ()
259
326
.resolve (new ResolveRequest (this , location ));
@@ -284,7 +351,8 @@ private int handleNavigation(UI ui, Location location,
284
351
}
285
352
286
353
private int handleExceptionNavigation (UI ui , Location location ,
287
- Exception exception , NavigationTrigger trigger , JsonValue state ) {
354
+ Exception exception , NavigationTrigger trigger ,
355
+ BaseJsonNode state ) {
288
356
Optional <ErrorTargetEntry > maybeLookupResult = getErrorNavigationTarget (
289
357
exception );
290
358
0 commit comments