javavaadinvaadin14

Pass the parameter in Vaadin 14 between two routes


Help me, please, to make navigating between views in vaadin application. In OrdersView class I create a link like

UI.getCurrent().navigate(FullOrderView.class, new RouteParameters("orderId", "123"));

In FullOrderView class I specify a route like this

@Route("order/:orderId")
public class FullOrderView extends AppLayout implements HasUrlParameter<String>{
    @Override
    public void setParameter(BeforeEvent event, String parameter) {
    }

but I get an error

java.lang.IllegalArgumentException: Navigation target 'com.example.crudwithvaadin.FullOrderView' requires a parameter.

If I remove a "implements HasUrlParameter" and setParameter() I get an error

No route found for the given navigation target 'com.example.crudwithvaadin.FullOrderView' and parameters '{}'

How do I fix the error and pass the parameter correctly? Thanks!


Solution

  • You are combining different Router features. The usage of Route template parameter (:orderId) has to be used in conjunction with BeforeEnterObserver instead of HasUrlParamter.