3

I have a master/detail situation. I'd like to employ a child router so that I can (a) make full use of the history module and (b) trigger the entrance transition on only the child. Here's my setup:

Shell.js

// configure the shell router
router.map([{ 
    ...
},{ 
    route: 'users*edit', 
    title: 'User List', 
    moduleId: 'viewmodels/users' 
}]).activate();

Users.js

this.router = router
    .createChildRouter()
    .makeRelative({ fromParent: true })
    .map({ route: ':id', moduleId: 'viewmodels/edit' })

When I navigate to #/users/5 it works brilliantly. However, when I navigate to #/users, as expected, it fires a route not found, cancels navigation, and returns me to #/users/5. How should I configure this to disable the child view when the route is not found? Ideally, I'd like to have something like this:

Users.js

this.router = router
    .createChildRouter()
    .makeRelative({ fromParent: true })
    .map([ 
        { route: ':id', moduleId: 'viewmodels/edit' },
        { route: '', moduleId: null }
])

where the router will successfully navigate to the '' route but the null parameter will instruct it to simply empty the router binding handler.

Matthew James Davis
  • 12,134
  • 7
  • 61
  • 90
  • 1
    You might want to check for `id` in `canActivate` and `return true;` if there's one and `return {redirect: 'emptyIdRoute'};` otherwise. – RainerAtSpirit Dec 31 '13 at 09:32
  • or, even easier would be to replace null in the second example with 'emptyIdRoute'. The problem is, I don't really want an empty view/model floating around. I'm looking for an instruction to tell the durandal router just to empty the router container. Thanks :) – Matthew James Davis Dec 31 '13 at 17:31

1 Answers1

2

This is not currently a feature of Durandal. I have added support for this kind of thing in a pull request, which you can find here, in case you would like to add support for null routes to your app.

Matthew James Davis
  • 12,134
  • 7
  • 61
  • 90