Passing parameters via router & _values[0]

Hi,

I’m trying to figure out how to pass a parameter to another page. As far as I understood any object can be passed through. So if i have a router with 2 pages PageA and PageB, and want to send a simple Observable from one to the other. I do:

<Page ux:Class="PageA">
	<Router ux:Dependency="router" />
	<JavaScript>
	var Observable = require("FuseJS/Observable");

	var my_param = new Observable("hey");

	module.exports = {
		input: my_param,
		go_to : function() {
			router.push("PageB", my_param)
		}
	}

	</JavaScript>
	<StackPanel>
		<TextInput Value="{input}" />
		<Button Clicked="{go_to}" Text="go"/>
	</StackPanel>
</Page>

and

<Page ux:Class="PageB">
	<Router ux:Dependency="router" />
	<JavaScript>
	var Observable = require("FuseJS/Observable");

	var p = this.Parameter.map(function(param) {
		console.log("\npage B")
		console.dir(param._values[0]);
		console.dir(param.value);
		return "...";
	});

	module.exports = {
		go_to : function() {
			router.goBack()
		},
		p
	}
	</JavaScript>
	<StackPanel>
		<Button Clicked="{go_to}" Text="go back"/>
	</StackPanel>
</Page>

However, as you can see in this.Parameter.map, value is null and _values[0] contains the right value…

Anyone has an idea how to fix this in a not too verbose way/what did I messed up please?

Thanks!

Hey!

As we discussed on Slack, the problem here is that passing Observables as parameters to router is currently not supported. What’s confusing is that it almost works: you get an object with the fields but none of the functions of the observable.

I’m not sure if this should be supported or if it should be an error, but I do know that the current behaviour is pretty confusing.

I’ve created an internal issue to track this.

Hi!

It is not allowed to pass observables as route parameters. Route parameters must be serializeable.

If you want to pass an observable, you need to keep it in a global module and use a route parameter to identify it.

OK thanks makes things clear!

Good to know that observables are not serializable.

We’ve now added better error handling so you will get a proper error message if trying to pass an observable or other non-serializeable structure as parameter. Thanks!