Open a new tab

How can I open a new tab with vaadin 14?


For other searching for this, here are four options. The open call below requires a String… I wish it would just take a LitElement class with a Route annotation. I’m sure there are like 17 other options =)

My preference from top to bottom:

// make a new RouterLink for the target and access the route string
RouterLink link = new RouterLink(null, ErrorLogView.class);
getUI().ifPresent(ui -> ui.getPage().open(link.getHref()));
// same as above but with the RouterLink messily buried in the open argument
getUI().ifPresent(ui -> ui.getPage().open((new RouterLink(null, ErrorLogView.class)).getHref()));
// getting the URL from the Route Annotation on the view class
getUI().ifPresent(ui -> ui.getPage().open(ErrorLogView.class.getAnnotation(Route.class).value()));
// static string; useful for pages on other websites
getUI().ifPresent(ui -> ui.getPage().open("/error-log"));