2
votes

Please help I have a splat route which looks like this.

admin*details

I created a child router from admin link like this.

var childRouter = router.createChildRouter().makeRelative({ moduleId: 'admin', route:'admin'})
    .map([
           {
            title: 'Case Files',
            route: 'default/index',
            moduleId: 'default/index',
            nav: true
           }
         ])
    .buildNavigationModel();


    var vm = {
        router: childRouter,
        activate: activate
    };

my folder structure is as like this.

viewmodels\admin\admin
viewmodels\admin\default\index

Why is it not navigating to the index page?
Instead I'm getting a Failed to load routed module error

2

2 Answers

0
votes

Whenever I create a child router I have always used the fromParent : true. Also the moduleId is taken from the root of the parent router, so you might find that something like this works

var childRouter = router.createChildRouter()
    .makeRelative({ moduleId: 'viewmodels/admin', fromParent: true})
    .map([{
        title: 'Case Files',
        route: 'default/index',
        moduleId: 'default/index',
        nav: true
       }])
    .buildNavigationModel();
0
votes

I think you have a very simple error here. When creating a child router you need to give the default route along with your route you are providing. I'm not saying it really well but here:

var childRouter = router.createChildRouter()
.makeRelative({ moduleId: 'admin', route:'admin'})
.map([
       {
        title: 'Case Files',
        route: ['', 'default/index'],
        moduleId: 'default/index',
        nav: true
       }
     ])
.buildNavigationModel();


var vm = {
    router: childRouter,
    activate: activate
};

You can also do it like this:

var childRouter = router.createChildRouter()
.makeRelative({ moduleId: 'admin', route:'admin'})
.map([
       {
        title:'Case Files',
        route: '',
        moduleId: 'default/index',
        nav: true
       },
       {
        title: 'Case Files',
        route: 'default/index',
        moduleId: 'default/index',
        nav: true
       }
     ])
.buildNavigationModel();


var vm = {
    router: childRouter,
    activate: activate
};

It seems that because you don't have that initial default child route, trying to go to /admin doesn't have a defined route, it expects /admin/default/index. Hope that helps.