Catching Invalid Hashes

Objective

After completing this lesson, you will be able to display a notification view if a hash is entered for which there is no matching route.

Invalid Hashes

If a user tries to access an invalid pattern that does not match any of the configured routes, they should be notified that something went wrong.

Screenshot of a browser displaying a resource is not available message.

To implement this feature, the bypassed property is available in the routing configuration. Using this property, you specify the navigation target that is used whenever no navigation pattern is matched. If you use this setting, you also have to define a corresponding target in the targets section.

Sample routing configuration highlighting the notFound target.

In the example shown, the routing configuration in the application descriptor has been extended by adding the bypassed property. It tells the router to display the notFound target in case no route matches the current hash.

The notFound target is configured in the targets section. It loads the XML view sap.training.exc.view.NotFound without animation (show transition) into the pages aggregation of the UI control with the app Id.

Note

To display routing related error messages on a view, you can use the sap.m.MessagePage control.