question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve navigation with query parameters

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:17 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
mstahvcommented, Jun 22, 2022

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.

1reaction
mstahvcommented, Jun 22, 2022

Looks like navigate(Class,QueryParameters) is missing as well. Should maybe add that in the same UX improvement patch as well 🤔

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use Query Parameters with Angular Router
If you are navigating to the route imperatively using Router.navigate , you will pass in query parameters with queryParams .
Read more >
Does Using Query Parameters For Routing/Navigation Have ...
I thought about using query parameters for inter-component routing (i.e. Navigating between component routes) for example: /store?route=tools; / ...
Read more >
Angular — Why you should start using query parameters to ...
Query parameters (or query string) is a part of an URL that assigns values to specified parameters. It is not anything special as...
Read more >
Query Parameters | Additional Guides | Routing and Navigation
Route parameters is the easiest way to pass extra information to a given route, and it should work for most common use cases....
Read more >
Improved handling of URLs with parameters
URL Parameters helps you control which URLs on your site should be crawled by Googlebot, depending on the parameters that appear in these...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found