Question

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));
Was it helpful?

Solution 2

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/).

OTHER TIPS

Another solution would be :

var params = {
  param1: "parameter",
  param2: "anotherparameter"
}
//notes : this object can contain arrays like knockout observable()
//or observableArray();

1.- create the object (params) in shell.js and map it to your route definition like bellow :

 { route: 'routestr/:id', moduleId: 'viewmodels/adir/mymodul', title: 'je suis', 
hash: '#routestr', nav:3, routobj: params }

2.- you could update, even add new members to your object from anywhere before calling this route, by hacking the object from the route.

var myrouteconfig = router.activeInstruction().config;
myrouteconfig.param2 = newvalue;
myrouteconfig.newdlyParam = value;
router.navigate("#routestr/" + id);

3.- Then, in the receipt module :

var activate = function (id) {
      //var myid = parseInt(id); //noelem rubriq                    
      var myrouteconfig = router.activeInstruction().config;
      var mycallobject = myrouteconfig.params; //your object params
      var valparam2 = mycallobject.param2; // your param2 last value
      ......
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top