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

AI-generated summary

In a discussion about extending built-in nested routes in Ember for the Discourse Solved plugin, sam initially attempted to add a custom route map file. However, sam reported that this approach overwrote existing routes and broke functionality, while using the resource mechanism failed to handle nested structures correctly. eviltrout initially suggested using a resource object with a map function to attach routes, but sam demonstrated via screenshots that this failed to map the nested path correctly. To resolve the issue, eviltrout rewrote the underlying route map logic in a commit. The final solution allows users to extend nested routes by specifying the full nested path in the resource key, as shown in the updated code: resource: 'user.userActivity'.

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?

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.

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

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');
  }
};