Record Class RouterState

java.lang.Object
java.lang.Record
com.vaadin.flow.router.RouterState
Record Components:
location - the location of the current view (path, query parameters, fragment); never null. Before the first navigation, this is an empty location (new Location("")).
routeParameters - route parameters extracted from the URL; never null. May be RouteParameters.empty().
activeChain - unmodifiable list of the currently active route target and its parent layouts, leaf first. Never null; empty before the first navigation completes.
navigationTarget - the class of the leaf route target. null before the first navigation completes.
All Implemented Interfaces:
Serializable

public record RouterState(Location location, RouteParameters routeParameters, List<HasElement> activeChain, Class<? extends Component> navigationTarget) extends Record implements Serializable
An immutable snapshot of a UI's current navigation state.

Carried by UI.routerStateSignal() so that components can observe the active route reactively, instead of registering an AfterNavigationListener and manually fetching the initial state on attach.

The snapshot covers the same data already available through AfterNavigationEvent plus the navigation target class. It is produced at the same point that AfterNavigationEvent is dispatched, so the signal value and the listener notification are always consistent.

See Also:
  • Constructor Details

  • Method Details

    • currentView

      public Optional<HasElement> currentView()
      Returns the currently shown leaf view, if any.
      Returns:
      the leaf route target, or empty if no navigation has happened yet
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • location

      public Location location()
      Returns the value of the location record component.
      Returns:
      the value of the location record component
    • routeParameters

      public RouteParameters routeParameters()
      Returns the value of the routeParameters record component.
      Returns:
      the value of the routeParameters record component
    • activeChain

      public List<HasElement> activeChain()
      Returns the value of the activeChain record component.
      Returns:
      the value of the activeChain record component