Skip to content

Commit 574db78

Browse files
committed
Did Step 5 of Navigation & Routing; Manual routing without changing the hash;
1 parent 1c39c78 commit 574db78

6 files changed

+52
-19
lines changed

webapp/controller/Home.controller.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
sap.ui.define([
2-
"com/mrb/UI5-Navigation-and-Routing/controller/BaseController"
3-
], function(BaseController) {
4-
"use strict";
5-
6-
return BaseController.extend("com.mrb.UI5-Navigation-and-Routing.controller.Home", {});
7-
});
8-
2+
"com/mrb/UI5-Navigation-and-Routing/controller/BaseController"
3+
], function (BaseController) {
4+
"use strict";
5+
6+
return BaseController.extend("com.mrb.UI5-Navigation-and-Routing.controller.Home", {
7+
onDisplayNotFound: function () {
8+
/*
9+
alternative ways of getting the `sap.m.routing.Targets` Object
10+
this.getOwnerComponent().getRouter().getTargets() or
11+
this.getOwnerComponent().getTargets().
12+
*/
13+
//display the "notFound" target without changing the hash
14+
this.getRouter().getTargets().display("notFound", {
15+
fromTarget: "home"
16+
});
17+
18+
}
19+
});
20+
});
+26-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
sap.ui.define([
2-
"com/mrb/UI5-Navigation-and-Routing/controller/BaseController"
2+
"com/mrb/UI5-Navigation-and-Routing/controller/BaseController"
33
], function (BaseController) {
4-
"use strict";
5-
return BaseController.extend("com.mrb.UI5-Navigation-and-Routing.controller.NotFound", {
6-
onInit: function () {
7-
}
8-
});
9-
});
4+
"use strict";
5+
return BaseController.extend("com.mrb.UI5-Navigation-and-Routing.controller.NotFound", {
6+
onInit: function () {
7+
var oRouter, oTarget;
8+
oRouter = this.getRouter();
9+
oTarget = oRouter.getTarget("notFound");
10+
oTarget.attachDisplay(function (oEvent) {
11+
this._oData = oEvent.getParameter("data"); // store the data
12+
}, this);
13+
},
14+
15+
// override the parent's onNavBack (inherited from BaseController)
16+
onNavBack: function () {
17+
// in some cases we could display a certain target when the back button is pressed
18+
if (this._oData && this._oData.fromTarget) {
19+
this.getRouter().getTargets().display(this._oData.fromTarget);
20+
delete this._oData.fromTarget;
21+
return;
22+
}
23+
24+
// call the parent's onNavBack
25+
BaseController.prototype.onNavBack.apply(this, arguments);
26+
}
27+
});
28+
});

webapp/i18n/i18n.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ iWantToNavigate=I want to navigate
55
homePageTitle=Home
66
NotFound=Not Found
77
NotFound.text=Sorry, but the requested resource is not available.
8-
NotFound.description=Please check the URL and try again.
8+
NotFound.description=Please check the URL and try again.
9+
DisplayNotFound=Display Not Found

webapp/i18n/i18n_en.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ iWantToNavigate=I want to navigate
55
homePageTitle=Home
66
NotFound=Not Found
77
NotFound.text=Sorry, but the requested resource is not available.
8-
NotFound.description=Please check the URL and try again.
8+
NotFound.description=Please check the URL and try again.
9+
DisplayNotFound=Display Not Found

webapp/view/Home.view.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:mvc="sap.ui.core.mvc">
55
<Page title="{i18n>homePageTitle}" class="sapUiResponsiveContentPadding">
66
<content>
7-
<Button text="{i18n>iWantToNavigate}" class="sapUiTinyMarginEnd"/>
8-
</content>
7+
<Button id="displayNotFoundBtn" text="{i18n>DisplayNotFound}" press=".onDisplayNotFound" class="sapUiTinyMarginEnd"/>
8+
</content>
99
</Page>
1010
</mvc:View>

webapp/view/NotFound.view.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
text="{i18n>NotFound.text}"
88
description="{i18n>NotFound.description}"
99
showNavButton="true"
10-
navButtonPress="onNavBack"/>
10+
navButtonPress="onNavBack"/>
1111
</mvc:View>

0 commit comments

Comments
 (0)