{{#link-to 'routeName'}} with dynamic context


#1

Is it possible to use link-to with dynamic context params as a single variable?

This works when there is 1 dynamic part, but in the example below i have post-category-id and post-id. Is it possible to pass these params in dynamically. It tried to pass them as array or as a String, but this is not working.

In the example I want to {{#link-to "post" params}} where post is nested in post-category. My goal is to pass in params with the 2 context params needed.

// router
this.resource('post-categories', {path: 'post-categories/:post-category-id'}, function() {
  this.resource('post', {path: 'post/:post-id'})
});

// controller
...
  params: Em.computed(function() {
    return [1, 4]
  })
...

// template
{{#link-to "post" params}}

I tried to read in the source, but that didn’t help too much.


#2

My workaround is using a controller action. In this action I check the length of my params and switch case transitionToRoute with the desired amount of dynamic parts. Though not verry DRY.

switch (params.length) {
  case 0: 
    this.transitionToRoute(route.get('routeName'))
  break;
  case 1: 
    this.transitionToRoute(route.get('routeName'), params[0])
  break;
  case 2: 
    this.transitionToRoute(route.get('routeName'), params[0], params[1])
  break;
  case 3: 
    this.transitionToRoute(route.get('routeName'), params[0], params[1], params[2])
}