0
votes

I am running into an issue setting up routes. I have a route group of

this.route('users', function () {

for

/users

/users/add

as well this.route('users', {path: '/users/:user_id'}, function () {

for routes like

/users/1/edit

/users/1/goals

/users/1/goals/1

The issue I have is that {{#link-to 'users'}}Users{{/link-to}} results in a link to "/users/undefined", which causes other issues, it needs to be "/users". Is there a way to do routes like this or would I be forced to have "users" and "user" route groups?

My routes:

this.route('users', function () {
  this.route('add');
});

this.route('users', {path: '/users/:user_id'}, function () {
  this.route('edit');
  this.route('goals', function(){
    this.route('add');
    this.route('edit', {path: '/:goal_id/edit'});
  });
});

UPDATE: ended up with

this.route('users', function () {
  this.route('add');
});

this.route('user', {path: '/user/:user_id'}, function () {
  this.route('edit');
  this.route('goals', function(){
    this.route('add');
    this.route('edit', {path: '/:goal_id/edit'});
  });
});

Also I needed to fix my branch route js, and learn about this.modelFor('user') to get parent model since params are consumed.

2

2 Answers

0
votes

It looks like you need to try nesting routes. It might look something like this:

this.route('users', function () {
  this.route('add');
});

this.route('user', {path: '/user/:user_id'}, function () {
  this.route('edit');
  this.route('goals', function(){
    this.route('add');
  });
  this.route('goal', {path: '/goal/:goal_id', function(){
    this.route('edit');
  });
});
1
votes

In your example, the paths with parameters only need to be on those routes that always have an ID in them:

this.route('users', function () {
  this.route('add');
  this.route('edit', {path: '/:id/edit'});
  this.route('goals', {path: '/:id/goals'}, function() {
    this.route('add');
    this.route('edit', {path: '/:goal_id/edit'});
  });
});