docs

Routing Configuration

Routing configuration consists of routes, targets, config, and owner.


Routes

Preferably, an array of routes is added to the router. Each route defines a name, a pattern, and optionally one or more targets to which to navigate when the route has been matched. In the routes section, you define which patterns are available for navigation. Routes need to be defined in an array instead of an object, because their order in the array determines the sequence when matching against the browser hash.

The sequence of the routes in the routes definition is important. As soon as a pattern is matched, the following patterns are ignored. To prevent this for a specific route, you use the greedy parameter. If set to true, the route is always taken into account.

For more information, see API Reference: sap.m.routing.Router.


Targets

A target defines the view or component that is displayed. It is associated with one or more routes or it can be displayed manually from within the app. Whenever a target is displayed, the corresponding view or component is loaded and added to the aggregation configured with the controlAggregation option of the control. The target definition can contain the following parameters:

Note:

You can also use targets without routes to call a view directly.For more information, see the tutorial Step 5: Display a Target Without Changing the Hash and Step 10: Implement “Lazy Loading”, and the sample Targets Without a Router in the Samples in the Demo Kit.

For more information, see API Reference: sap.m.routing.Router.


Config

The config section contains the global router configuration and default values that apply for all routes and targets. The config section contains the following settings.

For more information, see API Reference: sap.m.routing.Router.


Owner

The owner parameter defines the owner of all views that are created by the router. This is typically a UIComponent. This parameter is set automatically if the router instance is instantiated by a component.


Example

{
    metadata: {
        routing: {
            config: {
                async: true
                viewType: "XML",
                path: "view",
                controlId: "splitApp",
                clearTarget: false,
                bypassed: {
                    target: "notFound"
                },
                homeRoute: "home"
            },
            routes: [
                {
                    pattern: "",
                    name : "home",
                    target: "home"
                },
                {
                    pattern: "category/{id}",
                    name: "category",
                    target: "category"
                },
                {
                    pattern: "category/{id}/product/{productId}",
                    name: "product",
                    target: ["category", "product"]
                },
],
            targets: {
                category: {
                    type: "View",
                    name: "Category",
                    controlAggregation: "masterPages" 
                },
                product: {
                    type: "View",
                    name: "Product",
                    controlAggregation: "detailPages",
                },
                home: {
                    type: "View",
                    name: "Home",
                    controlAggregation: "masterPages"
                },
                notFound: {
                    type: "View",
                    name: "NotFound",
                    controlAggregation: "detailPages",
                    parent: "home"
                }
            }
        }
    }    
}

In this example, the Home view is always shown when the hash is empty. The Category view is shown when the hash matches the pattern category/{id}. Both, the Category and the Product view are shown when the hash matches the pattern category/{id}/product/{productId}, because both of them are added to the target property of the product route.

Related Information

API Reference: sap.ui.core.routing

API Reference: sap.m.routing.Router

Sample: Targets Without a Router

Working with Multiple Targets

Tutorial: Navigation and Routing

Enabling Routing in Nested Components