'SAPUI5 Routing/Navigation with Dynamic Targets results in Error: The target you tried to get "TargetXYZ" does not exist

after downgrading from SAPUI5 v1.97.0 to v1.78.8 (due to compatibility) I get errors when creating targets dynamically using sap.m.routing.Router.

I have a main controller in which I create the targets and routes to the nested views within the content section of the main view.

Before the version change it worked without any problems as follows:

aViews.forEach(function (item, index) {
    ...
    ...
    this._oRouter.getTargets().addTarget(sTargetName, {
        parent: "TargetMain",
        viewName: sViewName,
        viewPath: item.view.viewPath,
        viewType: "XML",
        viewLevel: 2,
        controlId: item.id,
        controlAggregation: "content"
    });

    this._oRouter.addRoute({
        name: "Route" + sViewName,
        pattern: sViewName + ":?query:",
        target: ["TargetMain", sTargetName]
    });
}.bind(this));

Now I get the following error displayed: The target you tried to get "TargetXYZ" does not exist! - EventProvider sap.m.routing.Targets

Any ideas to fix the error? Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source