class sap.m.routing.Router

Control sample: sap.m.routing.Router
Visiblity: public
UX Guidelines:
Implements:
Available since: N/A
Module: sap/m/routing/Router
Application Component: CA-UI5-CTR

SAPUI5 mobile Router. The difference to the sap.ui.core.routing.Router are the viewLevel, transition, and transitionParameters properties that you can specify in every Route or Target created by this router.


Constructor

Constructor for a new sap.m.routing.Router. See sap.ui.core.routing.Router for the constructor arguments.

new sap.m.routing.Router(oRoutes?, oConfig?, oOwner?, oTargetsConfig?)
Param Type Default Value Description
oRoutes? object object[]

may contain many Route configurations as sap.ui.core.routing.Route#constructor.
Each of the routes contained in the array/object will be added to the router.

One way of defining routes is an array:

[
    //Will create a route called 'firstRouter' you can later use this name in navTo to navigate to this route
    {
        name: "firstRoute"
        pattern : "usefulPattern"
    },
    //Will create a route called 'anotherRoute'
    {
        name: "anotherRoute"
        pattern : "anotherPattern"
    },
    //Will create a route for a nested component with the prefix 'componentPrefix'
    {
        pattern: "componentPattern",
        name: "componentRoute",
        target: [
             {
                 name: "subComponent",
                 prefix: "componentPrefix"
             }
        ]
    }
]

The alternative way of defining routes is an Object.
If you choose this way, the name attribute is the name of the property.

{
    //Will create a route called 'firstRouter' you can later use this name in navTo to navigate to this route
    firstRoute : {
        pattern : "usefulPattern"
    },
    //Will create a route called 'anotherRoute'
    anotherRoute : {
        pattern : "anotherPattern"
    },
    //Will create a route for a nested component with the prefix 'componentPrefix'
    componentRoute{
        pattern: "componentPattern",
        target: [
             {
                 name: "subComponent",
                 prefix: "componentPrefix"
             }
        ]
    }
}
The values that may be provided are the same as in sap.ui.core.routing.Route#constructor

oConfig? object

Default values for route configuration - also takes the same parameters as sap.ui.core.routing.Target#constructor.
This config will be used for routes and for targets, used in the router
Eg: if the config object specifies :


{ viewType : "XML" }

The targets look like this:
{
    xmlTarget : {
        ...
    },
    jsTarget : {
        viewType : "JS"
        ...
    },
    componentTarget: {
        type: "Component",
        name: "subComponent",
        id: "mySubComponent",
        options: {
            // the Component configuration:
            manifest: true
            ...
        },
        controlId: "myRootView",
        controlAggregation: "content"
    }
}
Then the effective config will look like this:
{
    xmlTarget : {
        viewType : "XML"
        ...
    },
    jsTarget : {
        viewType : "JS"
        ...
    },
	   componentTarget: {
        type: "Component",
        name: "subComponent",
        id: "mySubComponent",
        options: {
            // the Component configuration:
            manifest: true
            ...
        },
        controlId: "myRootView",
        controlAggregation: "content"
    }
}

Since the xmlTarget does not specify its viewType, XML is taken from the config object. The jsTarget is specifying it, so the viewType will be JS.

async? boolean false

@since 1.34. Whether the views which are loaded within this router instance asyncly.

oOwner? sap.ui.core.UIComponent

the Component of all the views that will be created by this Router,
will get forwarded to the sap.ui.core.routing.Views#constructor.
If you are using the componentMetadata to define your routes you should skip this parameter.

oTargetsConfig? object

the target configuration, see sap.m.routing.Targets#constructor documentation (the options object).
You should use Targets to create and display views. The route should only contain routing relevant properties.
Example:


    new Router(
    // Routes
    [
        {
            // no view creation related properties are in the route
            name: "startRoute",
            //no hash
            pattern: "",
            // you can find this target in the targetConfig
            target: "welcome"
        }
    ],
    // Default values shared by routes and Targets
    {
        viewNamespace: "my.application.namespace",
        viewType: "XML"
    },
    // You should only use this constructor when you are not using a router with a component.
    // Please use the metadata of a component to define your routes and targets.
    // The documentation can be found here: {@link sap.ui.core.UIComponent.extend}.
    null,
    // Target config
    {
         //same name as in the route called 'startRoute'
         welcome: {
             // All properties for creating and placing a view go here or in the config
             viewName: "Welcome",
             controlId: "app",
             controlAggregation: "pages"
         }
    })


Methods Overview

Method Description
sap.m.routing.Router.extend

Creates a new subclass of class sap.m.routing.Router with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.core.routing.Router.extend.

sap.m.routing.Router.getMetadata

Returns a metadata object for class sap.m.routing.Router.

getTargetHandler

Returns the TargetHandler instance.

sap.m.routing.Router.extend

Creates a new subclass of class sap.m.routing.Router with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.core.routing.Router.extend.

Param Type DefaultValue Description
sClassName string

Name of the class being created

oClassInfo object

Object literal with information about the class

FNMetaImpl function

Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class

sap.m.routing.Router.getMetadata

Returns a metadata object for class sap.m.routing.Router.

getTargetHandler

Returns the TargetHandler instance.