Search code examples
sapui5

What is the difference between sap.ui.core.routing.Router.navTo() and sap.m.routing.Targets.display()?


Let’s say we I have one route and one target:

"routes": [{
  "pattern": "modify",
  "name": "modify",
  "target": [
    "master",
    "modify"
  ]
}],
"targets": {
  "modify": {
    "viewName": "Modify",
    "viewId": "modify",
    "viewLevel": 2
  }
}

So I can access the route by this.getRouter().navTo("modify"), meanwhile I can access the target by this.getRouter().getTargets().display("modify"). Both API can carry parameter by the second argument. It seems to achieve the same effect.

I can access target without defining a route for it. So I did not quite understand why I need a route?

Ref: sap.m.routing.Targets and sap.ui.core.routing.Router


Solution

  • display displays the target view without changing the hash value in contrast to navTo.

    You can find more information in the tutorial "Display a Target Without Changing the Hash".


    Both API can carry parameter by the second argument. It seems to achieve the same effect.

    • The data in display method is for the display event handler. When the event is fired, the handler carries the data we passed earlier.
    • The parameter map we can pass to navTo is mandatory if the pattern actually awaits a parameter, e.g. if we've defined the pattern like this initially: "pattern": "modify/{id}". Check out "Navigate to Routes with Mandatory Parameters".