>

ko.routing: relative reference

Suppose we have these nested rules:

nested rule

Where the level 0 rule selects the View that shows a list of records in a grid, while the par parameter selects which record to show in a detail area. Suppose also that each grid row has a detail link that once clicked shows the record bound to the row in the detail area. How to implement the row link? 

Since each router remembers the context of all parameters of the current route, it is enough to specify the value of the par parameter that selects the record to be shown in the detail area:

detail link

Where id is the property of the model bound to the grid row that contains the record principal key.

The action binding is smart enough to build the complete url.

When the user clicks a detail link, since the section of the url that matches "#/nested/:view" doesn't change, the action function of the 0 level view doesn't fire, so the view isn't reloaded. Only the action function associated to "/:par?" fires again and loads the new record in the detail area.

In general, in case of nested rules:

  • The action binding needs to specify just the parameters associated to the levels that will change. In the previous example just the par parameter of the level 1 rule, since all level 0 parameters will not change.
  • The action functions are invoked starting from the one of the first level whose matching url section changes. In the previous example, since the section of the url that matches the level 0 rule doesn't change, the first action function invoked is the one of the level 1 matching rule.