Is it possible to add #fragment
part of URI in Vaadin 14 and RouterLink?
I can't find anything in Vaadin docs.
I need this to have fast access to a specific part of the view from another view.
Is it possible to add #fragment part of URI in Vaadin 14 and RouterLink?
No, that is not possible. There is a solution to your problem*, but RouterLink
does not have any means to define an url fragment so it would scroll to the HTML element with the given id.
*How could your needs be implemented instead:
Let your target view class implement HasUrlParameter<String>
(use @Wildcard annotation on setParameter, so that you also can navigate to this view without specifying a fragment-parameter).
In the setParameter method in your view, you then read the given parameter and if it's not empty you could execute some javascript that scrolls to the element with the given id. Now you can specify the fragment in the RouterLink like this:
new RouterLink("MyView", MyView.class, "#my-fragment");
Yes, this is not an optimal solution, not by a long shot, but if you really need it, you could do it.
Please create a ticket for adding API to RouterLink for defining url fragments in the github repo of vaadin-flow, if you want this to happen.