Search code examples
javascriptrouterdurandaldurandal-navigation

Navigate using router and pass an object as a query string


I have two modules that I want to connect by navigating from one to the other. Since there are going several parameters to be passed, I want to use query string. Is there a way to use the built-in router to navigate to a module and have my object arguments being passed like

var params = {
  param1: "parameter",
  param2: "anotherparameter"
}
router.navigate("theothermodule", params);

or do I have to manually parametrize the object into the url string and pass it to router.navigate like

router.navigate("theothermodule?" + $.param(params));

Solution

  • You have to manually parametrize the object into the url string and map in router.activate (http://durandaljs.com/documentation/Using-The-Router/).

    However you can share data with Events(http://durandaljs.com/documentation/Leveraging-Publish-Subscribe/) or Activation Data property in Composition binding(http://durandaljs.com/documentation/Using-Composition/).