Search code examples
durandaldurandal-2.0durandal-navigation

How to set a Splat route as Default route Durandal 2.0


My default route has child views, can I set a Splat route as Default route in Durandal 2.0 if yes how I tried something like below but it fails , basically I want to implement a childrouter in my default view how can I do this..

define(['plugins/router'], function (router) {
return {
    router: router,
    activate: function () {
        return router.map([                
            { route: 'knockout-samples*details',    moduleId: 'ko/index',title: 'Knockout Samples',  nav: true, hash: '#knockout-samples' }
        ]).buildNavigationModel()              
          .activate();
    }
};

});


Solution

  • If I understand you correctly then yes - you can have a splat as your default route. You would do something like this in your root shell:

    router.map({
        moduleId: "child/shell",
        route: "*details"
    });
    

    And then in your child's view model:

    var childRouter = rootRouter
        .createChildRouter()
        .makeRelative({ moduleId: "child" });
    
    // Uses "child/defaultPage" as the view model, and "#/" as the route
    childRouter.map({
        moduleId: "defaultPage",
        route: ""
    });
    

    Hope that helps.