0
votes

I want to add some routes dynamically to router. But it throws the following error:

A name has to be specified for every route - EventProvider sap.ui.core.routing.Router A @ sap-ui-core.js:88

The code that I used is as following:

for (var i = 0; i < aRoutes.length; i++) {
    var _name = aRoutes[i].name,
        _pattern = sPatternPrefix + aRoutes[i].pattern,
        _target = aRoutes[i].target;
    var oRoute = new sap.ui.core.routing.Route(oRouter, {
        name: _name,
        pattern: _pattern,
        target: _target
    }); 
    oRouter.addRoute(oRoute, oParent);
}

What could be the reason, While all name parameter has a valid string?

The error is not thrown when the Route is created, but it's thrown when I want to use addRoute function.

1
You did you get the reference to the oRouter? - zygimantus

1 Answers

1
votes

You don't need to create a Route. Just use the oConfig object as it described in the api of new sap.ui.core.routing.Route. Thus change your code like this:

for (var i = 0; i < aRoutes.length; i++) {
     oRouter.addRoute({
          "name" : aRoutes[i].name,
          "pattern" : sPatternPrefix + aRoutes[i].pattern,
          "target" : aRoutes[i].target
      }, oParent);
 }