Vaadin Current View or Location

You can use the following methods to retrieve the current view, location or the browser URL:

  • UIInternals#getActiveViewLocation() to get currently active Location
  • UIInternals#getActiveRouterTargetsChain() to get currently active route chain (a list of RouterLayout components with the active location component)
  • Page#fetchCurrentURL to asynchronously fetch the URL from the browser (documentation)
  • VaadinServletRequest.getRequestURL() as documented on StackOverflow but this one is buggy: flow #17602
  • UI.getCurrentView() is a handy utility method which consults getActiveRouterTargetsChain()

The location is also available in BeforeEnterObserver’s BeforeEnterEvent#getLocation() and AfterNavigationObserver’s AfterNavigationEvent#getLocation().

Written on December 12, 2023