1

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.

Community
  • 1
  • 1
ykaragol
  • 6,139
  • 3
  • 29
  • 56

2 Answers2

1

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.

  • 1
    The reason you would want to use query params and not a store is because then you use the ability to bookmark/share the url. – tarponjargon Feb 10 '17 at 04:49
0

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.

ykaragol
  • 6,139
  • 3
  • 29
  • 56