Search code examples
routesdurandalhottowel

Distinguish the parameter passed as a query string in hot towel template that uses durandal


I have a hot towel application that uses durandal for routing. One of the routes that is defined in config file looks as follows:

   {
     url: 'charts/:id',
     moduleId: 'viewmodels/charts',
     name: 'Charts',
     visible: false
   }

Charts is a viewmodel that displays data for patient id or agency id. From patient viewmodel I am sending patient id and from agency viewmodel I am sending agency id.

My question is how can I know in activate method of Charts viewmodel whether the parameter in url is patient id or agency id ?

vm.activate = function (routeData) {
   ////routeData will have routeData.id. How can I know if this is patient id or agency id ?
};

Solution

  • To achieve the described scenario, the easiest thing is to add a second parameter which will distinguish your calling type.

    Here is a sample route:

    {
     url: 'charts/:type/:id',
     moduleId: 'viewmodels/charts',
     name: 'Charts',
     visible: false
    }
    

    In your activate you should now have two parameters to check against

    vm.activate = function (routeData) {
      ////routeData.type, routeData.id
      if(routeData.type === "agency") {
      }
    };