Overriding the built-in back function with my own params

I need to overwrite the back button action with the function which uses parameters. I see that the function is being worked, but when I print the expected parameter (console.log in my back-button handler), when it writes that the parameter is undefined.

I have this in the view:
<view on-back="goBack('discard')">

And in app.js:
function goBack(navType) { console.log(navType); }

It shows me “undefined” in the console.
Please tell me what I’m doing wrong.

If you want to pass parameters to a function call directly from the XML then you need to use the $: notation and execute raw JS.

So if you update your code to the below then it should work as expected

<view on-back="$:goBack('discard')">

I changed it to on-back="$:goBack(‘discard’)", but it doesn’t work.
Now we use runtime version 4.77.0-rc+3.

Rather than passing in the “discard” string, you could define the function as on-back="discard()". If the “discard” needs to be a parameter, my suggestion would be to use a javascript or view variable to define the navType rather than passing in the string directly in the on-back function.

1 Like

Is it at all possible to pass in parameters to my on-back function? It seems not …

No, it is not currently possible to pass arguments to the on-back function.