To navigate back in an application, the user can use the browser's native Back button. However, this Back button always uses the browser history for navigating back. This means that if you start the application with a certain hash value in the browser and then press the Back button, the application is exited via this button.
To change this behavior, a separate Back button is implemented for the application in the example shown. In the implementation of the corresponding
onNavBack event handler method, the
sap/ui/core/routing/History module is used to access the navigation history of the SAPUI5 application. The
getPreviousHash method of the history object is employed to check if there is a previous hash value in the app history. If so, the application navigates to this previous hash via the browser's native history API. In this case, the functionality of the app's Back button matches the functionality of the native browser Back button.
However, if there is no previous hash, the application navigates to the route named
overview via the router. That is, it navigates to another page within the application, while using the native browser Back button in this case would exit the application.
The second parameter when calling the
navTo method is an empty object as no additional parameters are passed to the route. The third parameter has the value
true and makes sure that the hash is replaced, so that there will be no entry in the browser history.