cancel
Showing results for 
Search instead for 
Did you mean: 

Back button in fragments

Former Member
0 Kudos

i hope you're doing fine.

I am working on a sap fiori app & i am stuck in this problem for about 2 weeks with no result. I have a "create" fragment which is attached to "Detail" view.

When i open the "create" fragment and want to go back to the main detail view, the back button doesn't work therefore i have to refresh the app.

I guess the back button doesn't work the same way between views & between fragments.

Here's my back button function :

cancel: function() {

        var oHistory = sap.ui.core.routing.History.getInstance(),
            sPreviousHash = oHistory.getPreviousHash();

        if (sPreviousHash !== undefined) {
            // The history contains a previous entry
            history.go(-1);
        }

    },

here when i display sPreviousHash, it's undefined.

Any help would be much appreciated.

Accepted Solutions (0)

Answers (1)

Answers (1)

kammaje_cis
Active Contributor
0 Kudos

You basically need an Else condition here to navigate in case sPreviousHash is initial.

Replace "master" in the below code with the route where you want to navigate to.

			if (sPreviousHash !== undefined) {
				// The history contains a previous entry
				history.go(-1);
			} else {
				// Otherwise we go backwards with a forward history
				var bReplace = true;
				this.getRouter().navTo("master", {}, bReplace);
			}