Diff of navigations type

I have 2 ways to navigate between routes in Vaadin

RouterLink routerLink = new RouterLink("Voltar", Inbox.class);

and

UI.getCurrent().navigate(Inbox.class);

how is the diff between they?

when I use the second I got an error in my js and when I use the firs don’t

RouterLink creates a clickable link component that can be used to navigate to a view. The upside is that it’s an actual <a> element and it, for example, shows the target page when you hover the mouse over it. It’s also more accessible for people with screen readers.

But internally have some different between then? Because I have one component that run a js, and when I navigate using routerLink I my js works fine, and when I navigate using (UI.getCurrent().navigate(…)) my js dont receive the element and I got some error when try to use

element.$server

tks

Yes, they’re internally different. Note from the RouterLink JavaDoc:

 * The <code>href</code> attribute of {@link #getElement()} will only be
 * up-to-date when the component is attached to a UI.