com.vaadin.flow.router.

Class Router

  • All Implemented Interfaces:

    Serializable


    public class Router
    extends Object
    implements Serializable

    The router takes care of serving content when the user navigates within a site or an application.

    Since:

    1.0.

    Author:

    Vaadin Ltd

    See Also:

    Route, Serialized Form

    • Constructor Detail

      • Router

        public Router(RouteRegistry registry)

        Constructs a new router with the given route registry and a DefaultRouteResolver.

        Parameters:

        registry - the route registry to use, not null

    • Method Detail

      • initializeUI

        public void initializeUI(UI ui,
                                 VaadinRequest initRequest)

        Enables navigation for a new UI instance. This initializes the UI content based on the location used for loading the UI and sets up the UI to be updated when the user navigates to some other location.

        Parameters:

        ui - the UI that navigation should be set up for

        initRequest - the Vaadin request that bootstraps the provided UI

      • resolveNavigationTarget

        public Optional<NavigationState> resolveNavigationTarget(String pathInfo,
                                                                 Map<String,String[]> parameterMap)

        Resolve the navigation target for given path and parameter map using the router routeResolver.

        Parameters:

        pathInfo - the path relative to the application

        parameterMap - A mapping of parameter names to arrays of parameter values

        Returns:

        NavigationTarget for the given path and parameter map if found

      • navigate

        public int navigate(UI ui,
                            Location location,
                            NavigationTrigger trigger)

        Navigates the given UI to the given location.

        This method just shows the given location on the page and doesn't update the browser location (and page history). Use the UI.navigate(String, QueryParameters) method if you want to update the browser location as well.

        Parameters:

        ui - the UI to update, not null

        location - the location to navigate to, not null

        trigger - the type of user action that triggered this navigation, not null

        Returns:

        the HTTP status code resulting from the navigation

        See Also:

        UI.navigate(String), UI.navigate(String, QueryParameters)

      • navigate

        public int navigate(UI ui,
                            Location location,
                            NavigationTrigger trigger,
                            elemental.json.JsonValue state)

        Navigates the given UI to the given location. For internal use only.

        This method pushes to the browser history if the trigger is NavigationTrigger.ROUTER_LINK or NavigationTrigger.UI_NAVIGATE.

        Parameters:

        ui - the UI to update, not null

        location - the location to navigate to, not null

        trigger - the type of user action that triggered this navigation, not null

        state - includes navigation state info including for example the scroll position and the complete href of the RouterLink

        Returns:

        the HTTP status code resulting from the navigation

        See Also:

        UI.navigate(String), UI.navigate(String, QueryParameters)

      • getUrl

        @Deprecated
        public String getUrl(Class<? extends Component> navigationTarget)

        Deprecated. Url handling is moved to RouteConfiguration.getUrl(Class)

        Get the registered url string for given navigation target.

        Note! If the navigation target has a url parameter that is required then this method will throw and IllegalArgumentException.

        Parameters:

        navigationTarget - navigation target to get url for

        Returns:

        url for the navigation target

        Throws:

        IllegalArgumentException - if the navigation target requires a parameter

      • getUrl

        @Deprecated
        public <T,C extends Component & HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget,
                                                                                      T parameter)

        Deprecated. Url handling is moved to RouteConfiguration.getUrl(Class, Object)

        Get the url string for given navigation target with the parameter in the url.

        Note! Given parameter is checked for correct class type. This means that if the navigation target defined parameter is of type Boolean then calling getUrl with a String will fail.

        Type Parameters:

        T - url parameter type

        C - navigation target type

        Parameters:

        navigationTarget - navigation target to get url for

        parameter - parameter to embed into the generated url

        Returns:

        url for the navigation target with parameter

      • getUrl

        @Deprecated
        public <T,C extends Component & HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget,
                                                                                      List<T> parameters)

        Deprecated. Url handling is moved to RouteConfiguration.getUrl(Class, List)

        Get the url string for given navigation target with the parameters in the url.

        Note! Given parameter is checked for correct class type. This means that if the navigation target defined parameter is of type Boolean then calling getUrl with a String will fail.

        Type Parameters:

        T - url parameter type

        C - navigation target type

        Parameters:

        navigationTarget - navigation target to get url for

        parameters - parameters to embed into the generated url, not null

        Returns:

        url for the navigation target with parameter

      • getRoutesByParent

        @Deprecated
        public Map<Class<? extends RouterLayout>,List<RouteData>> getRoutesByParent()

        Deprecated. No replacement.

        Get all available routes collected by parent layout.

        Returns:

        map of parent url to route

      • resolve

        @Deprecated
        public static String resolve(Class<?> component,
                                                 Route route)

        Deprecated. Use RouteUtil.resolve(Class, Route) instead

        Gets the effective route path value of the annotated class.

        Parameters:

        component - the component where the route points to

        route - the annotation

        Returns:

        The value of the annotation or naming convention based value if no explicit value is given.