docs

Routing and Navigation

OpenUI5 offers hash-based navigation, which allows you to build single-page apps where the navigation is done by changing the hash. In this way the browser does not have to reload the page; instead there is a callback to which the app and especially the affected view can react. A hash string is parsed and matched against patterns which will then inform the handlers.

You use routing in the following cases:

Routing overview

In OpenUI5, navigation and routing is implemented using a “router” to forward the hash change and the data in the hash to one or more views of the app.

You use routes to notify your application that the hash has changed to a certain value. For each route, you define the pattern that can be used in the app implementation.

With targets, you define where a view or a component is loaded and where the view or component is shown on the UI. By referring to one or multiple targets in a route’s definition, you can load and show the views or components once the route’s pattern matches the current hash.

You configure routing in OpenUI5 in the descriptor file (manifest.json) (see Manifest (Descriptor for Applications, Components, and Libraries)) or in the Component.js file (see Components ) to have it available globally throughout your app, but you can also define routes and targets locally by calling the constructors of the classes, for example under the sap.ui.core.routing and sap.m.routing namespaces.

Note:

You can also define only routes or only targets, but then just have to make sure that you implement the counterpart elsewhere.


Routing Patterns

Whenever a hash is added to a URL, the router checks whether there is a route with a matching pattern. The first matching route is taken and the corresponding target view is called. The data provided with the hash are passed on to the target.

You can use the following kinds of patterns:

Tip:

For a better understanding about how patterns work and what matched parameters look like, see the following page in the Samples in the Demo Kit: sap.ui.core.sample.PatternMatching/preview.


Note:

OpenUI5 uses Crossroads.js for parsing the hash and the Hasher framework for manipulating the hash.

Related Information

Tutorial: Navigation and Routing

API Reference: sap.ui.core.routing

API Reference: sap.m.routing.Router

API Reference: sap.ui.core.routing.Route: Constructor Detail

Crossroads.js

Hasher framework on GitHub