> Markdown version of [URL generation](https://vaadin.com/docs/v10/flow/routing/tutorial-routing-url-generation). Section index: [llms.txt](https://vaadin.com/docs/v10/flow/llms.txt)

#### <a id="work-in-progress"></a>Work in progress

# <a id="url-generation"></a>URL generation

Router exposes methods to get the navigation URL for registered navigation targets.

For a normal navigation target the request is a simple as calling for `Router.getUrl(Class target)`

```java
@Route("path")
public class PathComponent extends Div {
  public PathComponent() {
    setText("Hello @Route!");
  }
}

public class Menu extends Div {
    public Menu() {
        String route = UI.getCurrent().getRouter()
                .getUrl(PathComponent.class);
        Anchor link = new Anchor(route, "Path");
        add(link);
    }
}
```

The returned url would in this case simply be resolved to **path**, but in the case where we have parent layouts that add path parts it might not be as simple to generate the path by hand.

## <a id="url-generation-for-navigation-target-with-parameter"></a>URL generation for navigation target with parameter

For navigation targets with required parameters the parameter is given to resolver and the returning string will then contain the parameter e.g. `Router.getUrl(Class target, T parameter)`

```java
@Route(value = "greet")
public class GreetingComponent extends Div
        implements HasUrlParameter<String> {

    @Override
    public void setParameter(BeforeEvent event,
            String parameter) {
        setText(String.format("Hello, %s!", parameter));
    }
}

public class ParameterMenu extends Div {
    public ParameterMenu() {
        String route = UI.getCurrent().getRouter()
                .getUrl(GreetingComponent.class, "anonymous");
        Anchor link = new Anchor(route, "Greeting");
        add(link);
    }
}
```
