Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError:this.getRouter is not a function

Tring to add an object route to the main route(table page), but return this.getRouter is not a function error.

In main Controller:

    onPress : function(oEvent) {
        this._showObject(oEvent.getSource());
    },

    _showObject : function (oItem) {
        this.getRouter().navTo("object", {
            objectId: oItem.getBindingContext().getProperty("task_id")
        });
    },

In Component.js(I've checked , it's already loaded, no error produced)

sap.ui.define(["sap/ui/core/UIComponent"],
function (UIComponent) {
    "use strict";

    return UIComponent.extend("cts.mobile.Component", {
        metadata : {
            rootView : "cts.mobile.view.TaskTest",
            routing : {
                "config": {
                    "routerClass": "sap.m.routing.Router",
                    "viewType": "XML",
                    "viewPath": "cts.mobile.view",
                    "controlId": "taskapp", //in task.view.xml
                    "controlAggregation": "pages",
                    "async": true
                },
                "routes": [
                    {
                        "pattern": "",
                        "name": "task",
                        "target": "task"
                    },
                    {
                        "pattern": "ProductCollection/{objectId}",
                        "name": "object",
                        "target": "object"
                    }
                ],
                "targets": {
                    "worklist": {
                        "viewName": "TaskTest",
                        "viewId": "TaskTest",
                        "viewLevel": 1
                    },
                    "object": {
                        "viewName": "Object",
                        "viewId": "object",
                        "viewLevel": 2
                    }
                }
            }
        },

        init : function () {
            UIComponent.prototype.init.apply(this, arguments);

            // Parse the current url and display the targets of the route that matches the hash
            this.getRouter().initialize();
        }

    });
}

);

this value in _showObject:

f {mEventRegistry: Object, oView: f}

How to fix this error?

like image 343
Tina Chen Avatar asked Jun 23 '26 05:06

Tina Chen


1 Answers

Try

return this.getOwnerComponent().getRouter();

Instead of what you now have in the getRouter function.

like image 52
rpanneel Avatar answered Jun 30 '26 17:06

rpanneel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!