How do I extend a built-in nested route in Ember?


(Sam Saffron) #1

Mainly a question for @eviltrout

I am trying to extend some of the internal routes for the solved plugin.

I tried adding assets/javascripts/discourse/solved-route-map.js with:

export default function() {
  this.route('user', { resetNamespace: true, path: '/users/:username'} , function() {
    this.route('userActivity', { resetNamespace: true, path: 'user-activity' } , function() {
      this.route('solved');
    });
  });
};

Trouble is that it blows away the existing routes and pretty much breaks everything, I also tries with resource using the other mechanism but it does not play nice with nested routes.

Any idea how I would go about doing this?


(Robin Ward) #2

This is not super well documented, but the route maps are actually designed just for this purpose!

You should be able to do this:

export default {
  resource: 'userActivity',
  map() { 
     this.route('solved');
  }
};

The resource key in the object tells my custom route map code to attach the routes inside that resource.


(Sam Saffron) #3

Yeah, I tried that but it fails to map right cause it is nested :frowning: :


(Robin Ward) #4

Okay, I got this working although it meant a 100% rewrite of how my route map worked!

https://github.com/discourse/discourse/commit/4e251eaf080cb3d77eca843a47a8a950060d2564

Using what I suggested above (with a small change) will now work:

export default {
  resource: 'user.userActivity',
  map() { 
    this.route('solved');
  }
};