Skip to content

Commit

Permalink
Did Step 5 of Navigation & Routing; Manual routing without changing t…
Browse files Browse the repository at this point in the history
…he hash;
  • Loading branch information
wridgeu committed Mar 15, 2020
1 parent 1c39c78 commit 574db78
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 19 deletions.
26 changes: 19 additions & 7 deletions webapp/controller/Home.controller.js
Original file line number Diff line number Diff line change
@@ -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", {});
});

"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"
});

}
});
});
33 changes: 26 additions & 7 deletions webapp/controller/NotFound.controller.js
Original file line number Diff line number Diff line change
@@ -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 () {
}
});
});
"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);
}
});
});
3 changes: 2 additions & 1 deletion webapp/i18n/i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
NotFound.description=Please check the URL and try again.
DisplayNotFound=Display Not Found
3 changes: 2 additions & 1 deletion webapp/i18n/i18n_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
NotFound.description=Please check the URL and try again.
DisplayNotFound=Display Not Found
4 changes: 2 additions & 2 deletions webapp/view/Home.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:mvc="sap.ui.core.mvc">
<Page title="{i18n>homePageTitle}" class="sapUiResponsiveContentPadding">
<content>
<Button text="{i18n>iWantToNavigate}" class="sapUiTinyMarginEnd"/>
</content>
<Button id="displayNotFoundBtn" text="{i18n>DisplayNotFound}" press=".onDisplayNotFound" class="sapUiTinyMarginEnd"/>
</content>
</Page>
</mvc:View>
2 changes: 1 addition & 1 deletion webapp/view/NotFound.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
text="{i18n>NotFound.text}"
description="{i18n>NotFound.description}"
showNavButton="true"
navButtonPress="onNavBack"/>
navButtonPress="onNavBack"/>
</mvc:View>

0 comments on commit 574db78

Please sign in to comment.