Routing can also be used in components.
Configuration
Initialization
Access
View ownership
To implement the navigation framework, configure and initialize the router. You can do this inside the component. First, define the routing metadata as follows:
metadata : { ... routing: { config: { // default values for routing viewType : "XML", viewPath: "default.path.view", clearTarget: false }, routes: { // contains routing configuration objects "myRouteName" : { name : , pattern : "FirstView/{from}", view : "myViewId" } } } ... }
The routing metadata has two parameters:
config contains the default values for every route; default values are overwritten by custom route values
routes contains an array of all routes defined by the component
The router now needs to be initialized by the component, for example in the init function.
init : function() { ... sap.ui.core.UIComponent.prototype.init.apply(this, arguments); // this component should automatically initialize the router! this.getRouter().initialize(); ... }
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.
All views that are generated by the router are automatically created in the context of the component.