Passing parameters between routes in Ember 2.x

1.2k Views Asked by At

While going from one route to another, I want to pass some data (especcially arrays). How is it possible?

Why can't we use query-params with arrays?

Is it a problem storing data in a specific service during transition?

Note: I know there are some old questions those are nearly the same with this question. But their selected answers are no more applicable for Ember 2.x. Those questions are: 1, 2.

2

There are 2 best solutions below

0
ykaragol On BEST ANSWER

UPDATED

After testing with "transition.data"; not updating the history seems as a problem for us. So we again use "queryParams". The constraint is: do not pass a complex object between routes

OLD ANSWER

I'm using transition object for this purpose in an action while routing as the following:

let transition = router.transitionTo(route, model);
transition.data[propName] = propValue;

Also I wrote a component to use this code as link-to.

1
Christian Stengel On

I´m not sure if queryparams won´t work with arrays as I only used it with single ids, but it would not be a good solutions even if it worked, there´s a limit on how much you can send by parameters and you should not bother any user with your data.

  1. Just create a model to save your data for local use, so you can simply use the ember store

  2. Use a service you´ll have to inject in every controller you want to use your data

I would prefer the model/store variant so you´ll be able to observe and just follow the normal flow which is also good if someone else has to maintain your code.