1

In order to share code between my different routes (they are mostly the same), I am trying to do the following:

/// Base classes (not real routes)

App.RouteMixin = Ember.Mixin.create({
    ...
});

App.BaseIndexRoute = Ember.Route.extend(App.RouteMixin, {
    ...
});

/// NODES

App.rNodesMixin = Ember.Mixin.create({
    ...
});

App.NodesIndexRoute = App.BaseIndexRoute.extend(App.rNodesMixin, {
    ...
});

App.NodesShowRoute = App.BaseShowRoute.extend(App.rNodesMixin, {
    ...
});

App.NodesEditRoute = App.BaseEditRoute.extend(App.rNodesMixin, {
    ...
});

App.NodesNewRoute = App.BaseNewRoute.extend(App.rNodesMixin, {
    ...
});

/// AGENTS

App.rNodesMixin = Ember.Mixin.create({
    ...
});

App.AgentsIndexRoute = App.BaseIndexRoute.extend(App.rAgentsMixin, {
    ...
});

App.AgentsShowRoute = App.BaseShowRoute.extend(App.rAgentsMixin, {
    ...
});

App.AgentsEditRoute = App.BaseEditRoute.extend(App.rAgentsMixin, {
    ...
});

App.AgentsNewRoute = App.BaseNewRoute.extend(App.rAgentsMixin, {
    ...
});

And suddently I am getting the following errors:

Assertion failed: The attempt to linkTo route 'nodes.index' failed. The router did not find 'nodes.index' in its possible routes: 'index'

The same pattern has worked for the controllers. Is it not possible to reuse code for the routes, with mixin/extend?

4

1 回答 1

1

我认为您的路由器映射有一些错误。我刚刚更改了路由器映射并且可以正常工作。看看这个Jsfiddle

我使用了以下配置:

App.Router.map(function() {
    this.resource("nodes", function(){
        // other routes
    });
    this.resource("agents", function(){
        // other routes
    });
});
于 2013-07-30T13:15:23.023 回答