Altering an Ember Route in a Plugin

(Steven Slade) #1

Continuing the discussion from Discourse.Route.buildRoutes is not a function:

I am confused as to how to alter a route from within a plugin. Is it different then just following the same file path from within the plugin? In my plugin I have plugin/assets/javascripts/discourse/routes/user-summary.js.es6 and I am adding this.controllerFor("user").set("forceExpand", true); …which will force the expanded profile view on summary.

export default Discourse.Route.extend({
  model() {
    this.controllerFor("user").set("forceExpand", true);
    return this.modelFor("User").summary();

If I change the source code on my local Discourse it works but when I enable my plugin it does nothing. Now, I have had trouble recently where another plugin’s changes were not being picked up and the reason resolved itself mysteriously, so it could be that again.

But just to be safe, is altering routes in plugins different then what I am doing?

(Robin Ward) #2

To modify a class you’ll need to use an initializer that looks up the ember class and reopens it. The code would look something like this:

  const UserSummaryRoute = container.lookupFactory('route:user-summary');
    model() { /* new code */ }