knockout.jsdurandalknockout-2.0durandal-2.0durandal-navigation

Durandal: Include splat inside compose binding


I have this splat route configured inside shell.js

 router.map([
   { route: 'projects*modal', title: 'Projects', moduleId: 'views/projects', nav: true },
]).buildNavigationModel();

and this is how I try to compose the view with some splat parameter inside custom modal view

<div data-bind="compose: 'views/projects/thisIsOptionalSplatParameter'"></div>

This doesn't work. It only work when I update it directly on addressbar.

So, how can I include some parameters inside compose binding to the route ?

I need to let the page know if I used it inside a modal or not.. So I need to pass something like this:

http://localhost/#projects/modalTrue

and retrieve it using activate function inside the projects page:

var isInModal;

activate: function(params)
{
   if (typeof params !== 'undefined' && params !== null && params.replace('/', '') === 'modalTrue')
        isInModal = true;
    else
        isInModal = false;
}

Any help would be greatly appreciated!
Thanks


Solution

  • Have you tried leveraging the activationData attribute for the compose binding? Your outer view may catch the route params, store it in an observable, which again is provided via activationData to the composed view.