# router.push passing function parameter

**URL:** <https://forums.fusetools.com/t/router-push-passing-function-parameter/3634>\
**Category:** How-to Discussions\
**Created:** [June 6, 2016, 10:13pm UTC](https://forums.fusetools.com/t/router-push-passing-function-parameter/3634 "2016-06-06T22:13:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaulin](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zaulin](https://forums.fusetools.com/u/zaulin)\
**Post date:** [June 6, 2016, 10:13pm UTC](https://forums.fusetools.com/t/router-push-passing-function-parameter/3634/1 "2016-06-06T22:13:45Z")

</div>

Hi,

is it possible to pass a function as a parameter in router.push?

this does not work for me:

somewhere.js:

```auto
    infoJSON = {
        param1: "param1 value",
        param2: "param2 value",

        onOkClick: function(response){
            console.log(response);
        }
    }

    router.push("rate", infoJSON);

```

rate.js

```auto
this.onParameterChanged(function(param) {
    console.log("param1: " + param.param1);
    console.log("param2: " + param.param2);
    okFunction = param.onOkClick;

    okFunction("test");
}

```

i get the first 2 values but then i get the following error: “okFunction is not a function”

---

<div class="post-metadata">

**Author:** ![contacto](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@contacto](https://forums.fusetools.com/u/contacto)\
**Post date:** [June 7, 2016, 12:06am UTC](https://forums.fusetools.com/t/router-push-passing-function-parameter/3634/2 "2016-06-07T00:06:44Z")

</div>

Hi!

you need to use

this.onParameterChanged(function(param) { console.log(JSON.stringify(param) })

with this you can get all parameter from route!

hope it helps!

---

<div class="post-metadata">

**Author:** ![Jake\_Taylor](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/jake_taylor/32/512_2.png) [@Jake\_Taylor](https://forums.fusetools.com/u/Jake_Taylor)\
**Post date:** [June 7, 2016, 2:42pm UTC](https://forums.fusetools.com/t/router-push-passing-function-parameter/3634/3 "2016-06-07T14:42:06Z")

</div>

Hi there,

It’s not currently possible to send functions through the Router. The router can only send serializable values, and functions are not generally serializable (even if they were, the context in which they execute could be entirely different).

---

<div class="post-metadata">

**Author:** ![zaulin](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zaulin](https://forums.fusetools.com/u/zaulin)\
**Post date:** [June 7, 2016, 3:08pm UTC](https://forums.fusetools.com/t/router-push-passing-function-parameter/3634/4 "2016-06-07T15:08:21Z")

</div>

thnx!

“not currently” means you plan to make it possible in the future? 🙂

what i try to do (very simplified example):

userPage: (ux+js)

here i have a text that shows the user name + button to edit that name

changeNamePage (ux+js):

displays a page where u can change the user name. If u click ok:

```auto
- it changes the display name on "userPage.ux" 
- router.back();

```

if u click cancel:

```auto
- router.back();

```

i would like to be able to send a callback function on the parameters when calling the “changeNamePage”. Of course that page is much more complex and that’s why i would like to have it as a class (and not just a popup).

(dunno if that was clear)

---

<div class="post-metadata">

**Author:** ![Jake\_Taylor](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/jake_taylor/32/512_2.png) [@Jake\_Taylor](https://forums.fusetools.com/u/Jake_Taylor)\
**Post date:** [June 7, 2016, 3:12pm UTC](https://forums.fusetools.com/t/router-push-passing-function-parameter/3634/5 "2016-06-07T15:12:29Z")

</div>

In this case, “not currently” does _not_ mean we plan to support this. You should not need to pass functions around via the Router 🙂

Is the reason you want to pass functions around so that another page that the Navigator instantiates will be able to make modifications to your data context? Perhaps there’s a way to do this where both the code that sends you to the name change page and the name change page itself can both `require` a module that represents your database/backing store, for example.

---

<div class="post-metadata">

**Author:** ![zaulin](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zaulin](https://forums.fusetools.com/u/zaulin)\
**Post date:** [June 7, 2016, 3:16pm UTC](https://forums.fusetools.com/t/router-push-passing-function-parameter/3634/6 "2016-06-07T15:16:39Z")

</div>

Thnx!!

i’ll try to solve it 🙂

---

<div class="post-metadata">

**Author:** ![Jake\_Taylor](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/jake_taylor/32/512_2.png) [@Jake\_Taylor](https://forums.fusetools.com/u/Jake_Taylor)\
**Post date:** [June 7, 2016, 3:17pm UTC](https://forums.fusetools.com/t/router-push-passing-function-parameter/3634/7 "2016-06-07T15:17:12Z")

</div>

Great! 🙂
