Improve navigation with query parameters
See original GitHub issueDescribe your motivation
Vaadin 14.8.11
Currently, if I want to navigate to a view by java class name and I want to add a query parameter, I need to write the following code:
RouteConfiguration configuration = RouteConfiguration
.forRegistry(UI.getCurrent().getInternals().getRouter().getRegistry());
String url = configuration.getUrl(BookingFreightView.class, HasUrlParameterFormat.getParameters(bookingReference));
Map<String, List<String>> queryParameters = Collections.singletonMap("prev_view", Collections.singletonList(prevView.name()));
UI.getCurrent().navigate(url, new QueryParameters(queryParameters));
Describe the solution you’d like
Please provide an additional overload for navigation: UI.navigate(Class, Object, QueryParameters)
and also a static factory QueryParameters.of(String, String)
so that the code can read:
UI.getCUrrent().navigate(BookingFreightView.class, bookingReference, QueryParameters.of("prev_view", prevView.name()));
Also provide QueryParameters.toString()
and equals()/hashCode()
, similar to RouteParameters
.
Alternatives considered
QueryParameter.simple()
still needs a map even though it’s a bit better; QueryParameter.fromString()
could work but will suffer from escaping issues.
For the massive UI.navigate() overload
- perhaps a builder pattern could help? Not sure though, they all require a trailing go()
call, which, when omitted, will simply run no navigation - that will be a frequent source of bugs. Not recommended:
UI.getCurrent().navigateTo(it -> it.view(Foo.class, param).queryParam("foo", "bar"))
or
new Navigation().route(Foo.class, param).queryParam("foo", "bar").go();
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:17 (16 by maintainers)
Top GitHub Comments
Now I actually figured out what the second object in
UI.navigate(Class, Object, QueryParameters)
was. @mvysny is using both “route parameters” and query parameters at the same time.Looks like
navigate(Class,QueryParameters)
is missing as well. Should maybe add that in the same UX improvement patch as well 🤔