on ‎2016 Feb 26 8:50 AM
Hello,
I want to navigate through my detail pages in my sapui5 application.
I have tried different ways, I used Target, Router with different functions like:
But in all of them I face with an error that is like:
Uncaught TypeError: Cannot read property 'getTargets' of undefined
Uncaught TypeError: Cannot read property 'getRouter' of undefined
....
Can anyone help me that what can be the problem?
Regards
Sep
Request clarification before answering.
Hi Sep,
Do you have an App .view.xml in ur project?
Has the Routing and targets been defined in the manifest.json file?
Regards,
Srinivasan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sep,
Check this sample: Plunker
Navigation logic is in app.controller.js file
Best Regards,
Sai Vellanki.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sai,
Thank alot for your response, when I use this function I have this error:
sap.ui.core.UIComponent.getRouterFor is not a function
I do not know what can be the problem... In all the function I will see this kinds of error.
This is my Main.view . here I define my splitapp
<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
controllerName="splitrouting.Main" xmlns:html="http://www.w3.org/1999/xhtml">
<SplitApp id="appId">
<masterPages>
<mvc:XMLView viewName="splitrouting.Master" id="master" />
</masterPages>
<detailPages>
<mvc:XMLView viewName="splitrouting.Detail" id="Detail1" />
<mvc:XMLView viewName="splitrouting.Detail2" id="Detail2" />
</detailPages>
</SplitApp>
</core:View>
This is my Component.js
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/model/json/JSONModel"
], function (UIComponent, JSONModel) {
"use strict";
return UIComponent.extend("splitrouting.Component", {
metadata: {
manifest: "json"
},
init: function () {
UIComponent.prototype.init.apply(this, arguments);
this.getRouter().initialize();
}
});
});
Detail.controller
sap.ui.controller("splitrouting.Detail", {
onPress : function () {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("Detail2");
}
This is Detail2.controller
sap.ui.controller("splitrouting.Detail2", {
onInit: function() {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
},
}
and this is msnifest.json
{
"sap.ui5": {
"_version": "1.1.0",
"rootView": "splitrouting.Main",
"dependencies": {
"minUI5Version": "1.30",
"libs": {
"sap.m": {}
}
},
},
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"viewPath": "splirouting",
"controlId": "appId",
"controlAggregation": "detailPages"
},
"routes": [
{
"pattern": "",
"name": "Main",
"target": "Main"
},
{
"pattern": "",
"name": "Detail",
"target": "Detail"
},
{
"pattern": "/Detail2",
"name": "Detail2",
"target": "Detail2"
}
],
"targets": {
"Main": {
"viewName": "Main"
},
"Detail": {
"viewName": "Detail"
},
"Detail2": {
"viewName": "Detail2"
}
}
}
}
}
could you please take a look at these code and see if you can see something is wrong?
Thanks alot
sep,
Hi s sin,
Please check your manifest.json file. I am getting a few mistakes when i paste your code into https://jsonformatter.curiousconcept.com/
Yeah Daniel is right!
You have one extra comma, one extra closing brace.
Your manifest will be something like this:
{
"sap.ui5": {
"_version": "1.1.0",
"rootView": "splitrouting.Main",
"dependencies": {
"minUI5Version": "1.30",
"libs": {
"sap.m": {}
}
}
},
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"viewPath": "splirouting",
"controlId": "appId",
"controlAggregation": "detailPages"
},
"routes": [{
"pattern": "",
"name": "Main",
"target": "Main"
}, {
"pattern": "",
"name": "Detail",
"target": "Detail"
}, {
"pattern": "/Detail2",
"name": "Detail2",
"target": "Detail2"
}],
"targets": {
"Main": {
"viewName": "Main"
},
"Detail": {
"viewName": "Detail"
},
"Detail2": {
"viewName": "Detail2"
}
}
}
}
Regards,
Sai Vellanki.
| User | Count |
|---|---|
| 6 | |
| 6 | |
| 5 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.