cancel
Showing results for 
Search instead for 
Did you mean: 

SAP UI5 can not nav back

0 Kudos

Hi experts,

I add a new view with a navback button. I can navTo this new page, but the navBack button does not work. Could you help me find out where I did wrong? My onNavBack is copied from Demo Kit. Thank you!

Seats.view.xml:

<mvc:View
	controllerName="learningui5.seatselection.controller.Seats"
	xmlns="sap.m"
	xmlns:mvc="sap.ui.core.mvc"
	xmlns:core="sap.ui.core"
	xmlns:semantic="sap.m.semantic"
	xmlns:form="sap.ui.layout.form">
	<semantic:FullscreenPage
		id="page"
		navButtonPress="onNavBack"
		showNavButton="true"
		title="Seats">
		<semantic:content>		
 		</semantic:content>
	</semantic:FullscreenPage>
</mvc:View>

Seats.controller.js:

sap.ui.define([
	"sap/ui/core/mvc/Controller",
	"sap/ui/core/routing/History",
	"sap/ui/core/UIComponent"
], function (Controller,History,UIComponent) {
	"use strict";
	return Controller.extend("learningui5.seatselection.controller.Seats", {
		onNavBack: function () {
			var oHistory = History.getInstance();
			var sPreviousHash = oHistory.getPreviousHash();

			if (sPreviousHash !== undefined) {
				window.history.go(-1);
			} else {
				var oRouter = UIComponent.getRouterFor(this);
				oRouter.navTo("app", {}, true);
			}
		}
	});
});

manifest.json:

"routing": {
			"config": {
				"routerClass": "sap.m.routing.Router",
				"viewType": "XML",
				"viewPath": "learningui5.seatselection.view",
				"controlId": "app",
				"controlAggregation": "pages",
				"async": true
			},
			"routes": [{
				"pattern": "seats",
				"name": "seats",
				"target": "seats"
			}, {
				"pattern": "app",
				"name": "app",
				"target": "app"
			}],
			"targets": {
				"seats": {
					"viewID": "seats",
					"viewName": "Seats",
					"viewLevel" : 2
				},
				"app": {
					"viewId": "app",
					"viewName": "App"
				}
			}
		}
saurabh_vakil
Active Contributor
0 Kudos

What error message(s) do you see in the browser console on clicking the back button?

0 Kudos

this.getRouter is not a function

Accepted Solutions (0)

Answers (1)

Answers (1)

maheshpalavalli
Active Contributor

In your code I dont see this.getRouter.. but anyways try below code to get router..

this.getOwnerComponent().getRouter()

BR

Mahesh