Skip to content

Latest commit

 

History

History
66 lines (39 loc) · 1.66 KB

initializing-and-accessing-a-routing-instance-acdb6cd.md

File metadata and controls

66 lines (39 loc) · 1.66 KB

Initializing and Accessing a Routing Instance

This topic describes how to initialize routing in a component and access the routing functions.

Initializing

You initialize the router in the component using the following code:

sap.ui.define([
    "sap/ui/core/UIComponent", ...
], function (UIComponent, ...) {
    "use strict";

    return UIComponent.extend("YourComponentClassName", {

        ...,

        init: function () {
            ...
            // call the init function of the parent
            UIComponent.prototype.init.apply(this, arguments);
            // this component should automatically initialize the router
            this.getRouter().initialize();
            ...
        }
    });
});

The router instance is automatically destroyed when the component is destroyed.

Accessing

To access the router and to use its functions, use the getRouter() function or the static getRouterFor function of the UI component. You can pass either a controller, or a view:

var oRouter = sap.ui.core.UIComponent.getRouterFor(this);

You can also use the getRouter function of your UI component:

var oRouter = this.getRouter();

All views that are generated by the router are automatically created in the context of the component. To access the router from a controller, use the getOwnerComponent() function to get the owner component, which provides the getRouter() function:

var oRouter = this.getOwnerComponent().getRouter();

Related Information

Components