routesdurandal-2.0

Child Routers durandal 2 HTML StarterKit


i trying to create child routes in durandal 2 starterkit as shown in http://durandaljs.com/documentation/Using-The-Router/ without success.

i want to habe something like http://mywebsite.com/#blog/post1/

so in my app i have in viewmodel a shell file viewmodel/shell.js

{ route: 'blog*details', title:'Blog', moduleId: 'blog/index', nav: 2, hash: '#blog' },

and

in app/blog/

i have

index.js 
       index.js
       default/index.js
       default/index.html

why is it not working what am i doing wrong ?

thx

EDIT:

this is how my shell.js looks like

define(['plugins/router', 'durandal/app'], function (router, app) {

    return {
        router: router,
        attached : attached,
        search: function() {
            //It's really easy to show a message box.
            //You can add custom options too. Also, it returns a promise for the user's response.
            app.showMessage('Search not yet implemented...');
        },
        activate: function () {
            router.map([
                { route: '', title:'Home', moduleId: 'viewmodels/home', nav: 1 },
                { route: 'blog*route', title:'Blog', moduleId: 'blog/index', nav: 2, hash: '#blog' }
            ]).buildNavigationModel();

            return router.activate();
        },
        footerLinks : [
          ...
       ]
    };

      function attached() {

    }//=======attached end
});

Solution

  • One method is you will need to create a child router to handle your splat routes blog*details in your index.js file (so app/blog/index.js) you will need to create the child router like so.

    define(['plugins/router'],function(router){
        var childRouter = router.createChildRouter().makeRelative({ moduleId: 'blog', fromParent: true})
            .map([
                ...insert routes here...
            ]).buildNavigationModel();
        return {
            router: childRouter
        };
    });
    

    from then you can create all your routes like blog/post1, blog/post2 etc. Take a look at the samples in the ko folder of the HTML Samples.zip download