From 574db78c3f2210b479f21e41b6852da455c4e232 Mon Sep 17 00:00:00 2001 From: Marco Beier Date: Sun, 15 Mar 2020 20:48:25 +0100 Subject: [PATCH] Did Step 5 of Navigation & Routing; Manual routing without changing the hash; --- webapp/controller/Home.controller.js | 26 ++++++++++++++----- webapp/controller/NotFound.controller.js | 33 +++++++++++++++++++----- webapp/i18n/i18n.properties | 3 ++- webapp/i18n/i18n_en.properties | 3 ++- webapp/view/Home.view.xml | 4 +-- webapp/view/NotFound.view.xml | 2 +- 6 files changed, 52 insertions(+), 19 deletions(-) diff --git a/webapp/controller/Home.controller.js b/webapp/controller/Home.controller.js index 4c335fc..918a28e 100644 --- a/webapp/controller/Home.controller.js +++ b/webapp/controller/Home.controller.js @@ -1,8 +1,20 @@ sap.ui.define([ - "com/mrb/UI5-Navigation-and-Routing/controller/BaseController" - ], function(BaseController) { - "use strict"; - - return BaseController.extend("com.mrb.UI5-Navigation-and-Routing.controller.Home", {}); - }); - \ No newline at end of file + "com/mrb/UI5-Navigation-and-Routing/controller/BaseController" +], function (BaseController) { + "use strict"; + + return BaseController.extend("com.mrb.UI5-Navigation-and-Routing.controller.Home", { + onDisplayNotFound: function () { + /* + alternative ways of getting the `sap.m.routing.Targets` Object + this.getOwnerComponent().getRouter().getTargets() or + this.getOwnerComponent().getTargets(). + */ + //display the "notFound" target without changing the hash + this.getRouter().getTargets().display("notFound", { + fromTarget: "home" + }); + + } + }); +}); diff --git a/webapp/controller/NotFound.controller.js b/webapp/controller/NotFound.controller.js index f6443b9..5ba8fcd 100644 --- a/webapp/controller/NotFound.controller.js +++ b/webapp/controller/NotFound.controller.js @@ -1,9 +1,28 @@ sap.ui.define([ - "com/mrb/UI5-Navigation-and-Routing/controller/BaseController" + "com/mrb/UI5-Navigation-and-Routing/controller/BaseController" ], function (BaseController) { - "use strict"; - return BaseController.extend("com.mrb.UI5-Navigation-and-Routing.controller.NotFound", { - onInit: function () { - } - }); -}); \ No newline at end of file + "use strict"; + return BaseController.extend("com.mrb.UI5-Navigation-and-Routing.controller.NotFound", { + onInit: function () { + var oRouter, oTarget; + oRouter = this.getRouter(); + oTarget = oRouter.getTarget("notFound"); + oTarget.attachDisplay(function (oEvent) { + this._oData = oEvent.getParameter("data"); // store the data + }, this); + }, + + // override the parent's onNavBack (inherited from BaseController) + onNavBack: function () { + // in some cases we could display a certain target when the back button is pressed + if (this._oData && this._oData.fromTarget) { + this.getRouter().getTargets().display(this._oData.fromTarget); + delete this._oData.fromTarget; + return; + } + + // call the parent's onNavBack + BaseController.prototype.onNavBack.apply(this, arguments); + } + }); +}); diff --git a/webapp/i18n/i18n.properties b/webapp/i18n/i18n.properties index 1b61420..9a766f5 100644 --- a/webapp/i18n/i18n.properties +++ b/webapp/i18n/i18n.properties @@ -5,4 +5,5 @@ iWantToNavigate=I want to navigate homePageTitle=Home NotFound=Not Found NotFound.text=Sorry, but the requested resource is not available. -NotFound.description=Please check the URL and try again. \ No newline at end of file +NotFound.description=Please check the URL and try again. +DisplayNotFound=Display Not Found \ No newline at end of file diff --git a/webapp/i18n/i18n_en.properties b/webapp/i18n/i18n_en.properties index 1b61420..9a766f5 100644 --- a/webapp/i18n/i18n_en.properties +++ b/webapp/i18n/i18n_en.properties @@ -5,4 +5,5 @@ iWantToNavigate=I want to navigate homePageTitle=Home NotFound=Not Found NotFound.text=Sorry, but the requested resource is not available. -NotFound.description=Please check the URL and try again. \ No newline at end of file +NotFound.description=Please check the URL and try again. +DisplayNotFound=Display Not Found \ No newline at end of file diff --git a/webapp/view/Home.view.xml b/webapp/view/Home.view.xml index 3b431b6..963e671 100644 --- a/webapp/view/Home.view.xml +++ b/webapp/view/Home.view.xml @@ -4,7 +4,7 @@ xmlns:mvc="sap.ui.core.mvc"> -