Pass a variable in UI.navigation

I want to pass a variable to a page. I have 4 different buttons that have a ClickListener that navigates to the page, and I want also pass 4 possible different values. The first idea was using the URL:

localhost:8080/second-page?value=1

I try to find a way to get value from it, but nothing wants to work.

I try also a different way using the plug-in URL Parameter Mapping but return only null values.

Any idea?

Please show us what you’ve tried. What you are looking for are QueryParameter available in all Before and AfterEnterEvents’ Location Object.

What @knoobie said.
This example code should work for your case:

@Route("second-page")
public class SecondPage extends VerticalLayout implements HasUrlParameter<Integer> {

    @Override
    public void setParameter(BeforeEvent beforeEvent, @OptionalParameter Integer parameter) {
        // prints '1' for localhost:8080/second-page?value=1
        beforeEvent.getLocation().getQueryParameters().getSingleParameter("value")
                .ifPresent(System.out::println);
    }
}

Adding to @knoobie and @mikhail.21 comments, make sure to read about the Navigation Lifecycle. Parameters are read/processed before the view itself is built and need to be saved to variables than can then be read from your constructor/initialization methods.