# I can't retrieve custom parameters passed to the router.

**URL:** <https://forums.fusetools.com/t/i-cant-retrieve-custom-parameters-passed-to-the-router/2687>\
**Category:** How-to Discussions\
**Created:** [September 22, 2016, 4:04pm UTC](https://forums.fusetools.com/t/i-cant-retrieve-custom-parameters-passed-to-the-router/2687 "2016-09-22T16:04:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vam.system](https://avatars.discourse-cdn.com/v4/letter/v/8edcca/32.png) [@vam.system](https://forums.fusetools.com/u/vam.system)\
**Post date:** [September 22, 2016, 4:04pm UTC](https://forums.fusetools.com/t/i-cant-retrieve-custom-parameters-passed-to-the-router/2687/1 "2016-09-22T16:04:58Z")

</div>

Hello fuse community! I’ve updated to version 0.25.5 and I have a problem with this.Parameter, I’ve changed some code lines from the [hikr example](https://github.com/fusetools/hikr). The problem is that I can’t retrieve custom parameters that I’ve passed to the router. Please tell me what am I doing wrong please?. These are my changes:

**File: HomePage.js**

```auto
...
function goToHike(arg) {
	console.log('Selected index: ' + Context.hikes.indexOf(arg.data)); // This return the index successfully
	
	var params = { "index": Context.hikes.indexOf(arg.data) };
	
	router.push("editHike", params);
}
...

```

**File: EditHikePage.js**

```auto
var Context = require("Modules/Context");
var Observable = require("FuseJS/Observable");

var params = this.Parameter;
var hike = Observable(Context.hikes.getAt(params.value.index));
...

```

---

<div class="post-metadata">

**Author:** ![KaMeKuN](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@KaMeKuN](https://forums.fusetools.com/u/KaMeKuN)\
**Post date:** [September 23, 2016, 7:02pm UTC](https://forums.fusetools.com/t/i-cant-retrieve-custom-parameters-passed-to-the-router/2687/2 "2016-09-23T19:02:10Z")

</div>

You find the soliction for this? im trying to do the same. to make a fetch(url) from the hike params but with no success.

Someody know the issue?

i want to do it like this:

```auto
var api = hike.map(function(x) { return x.api; });
fetch("http://xxx.com/Api/gallery/" + api.value)....
module.exports = {
	name: name,
	api: api	
}

```

Return undefinied, but inside them method i can see the value of of api var.

---

<div class="post-metadata">

**Author:** ![vam.system](https://avatars.discourse-cdn.com/v4/letter/v/8edcca/32.png) [@vam.system](https://forums.fusetools.com/u/vam.system)\
**Post date:** [September 24, 2016, 5:38am UTC](https://forums.fusetools.com/t/i-cant-retrieve-custom-parameters-passed-to-the-router/2687/3 "2016-09-24T05:38:26Z")

</div>

I’ve been doing testing of several solutions, but nothing works. But!!! Actually, I’ve found that every javascript module executes once before you return the module object. Then, when a module is required you’ll get just the previous instance. **Read the comments on code.**

```auto
// The first time you require this module, Fuse runs javascript from here
var api = hike.map(function(x) { return x.api; });
fetch("http://xxx.com/Api/gallery/" + api.value)...
...
...
// The following lines returns the module's object 
// so, the next time you require the module Fuse will remenber the last instance of this module
// and only return the object
module.exports = {
    name: name,
    api: api    
};

```

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [September 25, 2016, 4:00am UTC](https://forums.fusetools.com/t/i-cant-retrieve-custom-parameters-passed-to-the-router/2687/4 "2016-09-25T04:00:09Z")

</div>

Hi!

The parameter is _asyncronously_ passed to your module. This means you cannot access `this.Parameter.value` immediately, you have to do that from inside the `map` function. This is the pattern:

```
this.Parameter.map(function(param) { 
    ... here use param ...

```

For example, to do an asynchronous `fetch()` call based on the parameter, do:

```
var data = this.Parameter.map(function(param) {
   var result = Observable(); 
    fetch(...).then(function(r) {
        result.value = r;
    })
    return result;
}).inner();

module.exports = { data: data }
```

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [September 25, 2016, 4:03am UTC](https://forums.fusetools.com/t/i-cant-retrieve-custom-parameters-passed-to-the-router/2687/5 "2016-09-25T04:03:40Z")

</div>

Alternatively you can also use `.onValueChanged`:

```
var data = Observable();

this.Parameter.onValueChanged(module, function(param) {
   somethingAsync().then(function(r) {
       data.value = r;
   })
});

module.exports = { data: data }
```

---

<div class="post-metadata">

**Author:** ![KaMeKuN](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@KaMeKuN](https://forums.fusetools.com/u/KaMeKuN)\
**Post date:** [September 26, 2016, 3:52pm UTC](https://forums.fusetools.com/t/i-cant-retrieve-custom-parameters-passed-to-the-router/2687/6 "2016-09-26T15:52:57Z")

</div>

Thanks you, this do the trick i wanted.  
inside the then i have a for of data to display a pictures like this:

```auto
for(var i in data) {
   var item = data[i];			
   pictures.add(item);		
}

```

do you know how i can cache the result so i dont need to call the api again?, the pictures are cached after the first load, but i think this can be improved.

---

<div class="post-metadata">

**Author:** ![vam.system](https://avatars.discourse-cdn.com/v4/letter/v/8edcca/32.png) [@vam.system](https://forums.fusetools.com/u/vam.system)\
**Post date:** [September 27, 2016, 12:28am UTC](https://forums.fusetools.com/t/i-cant-retrieve-custom-parameters-passed-to-the-router/2687/7 "2016-09-27T00:28:57Z")

</div>

That’s not documented on Fuse documentation, I really appreciate your answer, thank you very much.
