cancel
Showing results for 
Search instead for 
Did you mean: 

i got Cannot read property 'navTo' of undefined error . whats wrong with my code !!!

former_member691856
Discoverer
0 Kudos

hello everyone,

I tried the following code but it's not working.

fragment

AddProductHierarchySet.fragment.xml

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:tnt="sap.tnt" xmlns:l="sap.ui.layout">

<Dialog title="PRODUCT HIERARCHY SET INFORMATION" contentHeight="70%" contentWidth="70%">

<content>

<mvc:XMLView viewName="Rmanagement.FRebateManagement.view.CollectionGroupDetails"/>

</content>

<endButton>

<Button text="Close" press="onCloseFragment"/>

</endButton>

</Dialog>

</core:FragmentDefinition>

manifest.json:

view

collectionGroupDetails.view.xml:

collectionGroupDetails.controller.js

Accepted Solutions (0)

Answers (4)

Answers (4)

prashil
Advisor
Advisor

Hi Abhishek,

I see no reason why you should not get the router object.

Since I do not know the complete router configuration. Please also validate it is as specified in the documentation.

The passed controller or view has to be created in the context of a UIComponent to return the router instance. Otherwise this function will return undefined. You may define the routerClass property in the config section of the routing to make the Component create your router extension.

If this also doesn't work, try getting the router object from component itself.

var oRouter = this.getOwnerComponent().getRouter();

Thanks

Prashil

former_member691856
Discoverer
0 Kudos

Hi Prashil,

let me share my router configuration with you.

prashil
Advisor
Advisor
0 Kudos

Hi Abhishek,

{
    "_version": "1.3.0",
    "sap.app": {
        "_version": "1.3.0",
        "id": "com.prashil.test",
        "type": "application",
        "resources": "resources.json",
        "i18n": "i18n/i18n.properties",
        "title": "{{appTitle}}",
        "description": "{{appDescription}}",
        "applicationVersion": {
            "version": "${project.version}"
        },
        "ach": "XX",
        "dataSources": {
            "mainService" : {
                "uri": "/api/users",
                "type" : "OData",
                "settings": {
                    "odataVersion": "2.0"
                }
            }
        },
        "sourceTemplate": {
            "id": "test",
            "version": "1.0.0"
        }
    },
    "sap.fiori": {
        "_version": "1.1.0",
        "registrationIds": [],
        "archeType": "transactional"
    },
    "sap.ui": {
        "_version": "1.3.0",
        "technology": "UI5",
        "icons": {
            "icon": "sap-icon://detail-view",
            "favIcon": "",
            "phone": "",
            "phone@2": "",
            "tablet": "",
            "tablet@2": ""
        },
        "deviceTypes": {
            "desktop": true,
            "tablet": true,
            "phone": true
        },
        "supportedThemes": [
            "sap_hcb",
            "sap_bluecrystal"
        ]
    },
    "sap.ui5": {
        "_version": "1.2.0",
        "rootView": {
            "viewName": "com.prashil.test.view.App",
            "type": "XML",
            "id": "app"
        },
        "dependencies": {
            "minUI5Version": "${sap.ui5.dist.version}",
            "libs": {
                "sap.ui.core": {
                    "minVersion": "1.36.0"
                },
                "sap.m": {
                    "minVersion": "1.36.0"
                }
            }
        },
        "contentDensities": {
            "compact": true,
            "cozy": true
        },
        "models": {
            "i18n": {
                "type": "sap.ui.model.resource.ResourceModel",
                "settings": {
                    "bundleName": "com.prashil.test.i18n.i18n"
                }
            },
            "": {
                "dataSource": "mainService",
                "settings": {
                    "metadataUrlParams": {
                        "sap-documentation": "heading"
                    }
                }
            }
        },
        "routing": {
            "config": {
                "routerClass": "sap.m.routing.Router",
                "viewType": "XML",
                "viewPath": "com.prashil.test.view",
                "controlId": "idAppControl",
                "controlAggregation": "pages",
                "clearControlAggregation" : false,
                "bypassed": {
                    "target": [
                        "master",
                        "notFound"
                    ]
                },
                "async": true
            },
            "routes": [
                {
                    "pattern": "",
                    "name": "Main",
                    "target": [
                        "main"
                    ]
                },
                {
                    "pattern": "newPage/type/:idType/value/:idValue",
                    "name": "newPage",
                    "target": "detail"
                }
      ],
            "targets": {
                "main": {
                    "viewName": "Main",
                    "viewLevel": 1,
                    "viewId": "master",
                    "controlAggregation": "pages"
                },
                "detail": {
                    "viewName": "Detail",
                    "viewLevel": 1,
                    "viewId": "detail",
                    "controlAggregation": "pages"
                },
                "sflight": {
                    "viewName": "SFlight",
                    "viewLevel": 1,
                    "viewId": "flight",
                    "controlAggregation": "pages"
                }
            }
        }
    }
}


Thanks

Prashil

prashil
Advisor
Advisor
0 Kudos

Hi Abhishek,

Again, I tried similar code and for me it all worked well.

Few things that I avoided that you can also check, you have multiple controlId's in your target. I am not sure about the intention behind it but usually, this should be the control id of your App control.

Secondly, your have id "idApp" for your control and your target as well.

If your view Tile is the rootView then it should have been added as the rootView inside "sap.ui5" and no in routing.

Try fixing the above point and share the specific error your are facing.

Thanks

Prashil

former_member691856
Discoverer
0 Kudos

Hi Prashil,

could you share your manifest.json file?

prashil
Advisor
Advisor
0 Kudos

Hi Abhishek,

One point is the routing name "AddCollectionItem" has two arguments "groupId" and "itemId", while you are using only "groupId".

As per the error, you are not getting the router object, please check if you have initialized router in your component.js using

this.getRouter().initialize();

Thanks

Prashil

former_member691856
Discoverer
0 Kudos

Hi Prashil,

I remove the unwanted ID's. I initialized the router in component.js. bt still not working !!!!