avatar image
Former Member

Back button in fragments

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • May 10, 2017 at 03:49 AM

    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);
    			}
     
    Add comment
    10|10000 characters needed characters exceeded

Skip to Content