nathanhammond / ember-route-alias

Ember addon to create multiple paths for the same route.
http://nathanhammond.github.io/ember-route-alias/
MIT License
29 stars 18 forks source link

`this.modelFor('parent')` returns undefined when a route is entered via its alias #26

Open arnebit opened 6 years ago

arnebit commented 6 years ago

When a route with subroutes has an alias, then accessing the parent model in a subroute via this.modelFor requires knowing whether the route was accessed via the alias or the original name.

Moreover, transitioning between /one/a and /alias-one/a re-triggers one's model hook and this.modelFor('one') in ...routes/one/a.js will still return the old model hook result (i.e. from the previous transition to /one/a).

Testcase: Add two files:

/tests/dummy/app/routes/one/a.js
import Route from '@ember/routing/route';

export default Route.extend({
  model() { return `parent model is '${this.modelFor('one')}' (alias-model is '${this.modelFor('alias-one')}')`; }
})
/tests/dummy/app/routes/one.js
import Route from '@ember/routing/route';

export default Route.extend({
  model() { return `dummy model ${new Date().toTimeString()}`; }
})

Then show the model in tests/dummy/app/templates/a.hbs (and possibly alias-a.hbs), e.g. by adding <em> {{model}} </em> and navigate a bit between /one/a, alias-one/a and other routes.

Here, too, I am not sure this behaviour can be mitigated, but since I found it quite astonishing I would have preferred to learn about it from the readme.

brokenalarms commented 4 years ago

Yes, I'm not really getting how this package can be used for an dynamic routing. We have

      this.route('campaigns'); // this is the index, done before good Ember pattern of using index file
      this.route('campaign', { path: 'campaign/:campaign_id' }, function() {
        this.route('details');
      });

And I want to alias the campaign resource to be standardized plural if navigating within it: this.alias('campaigns', 'campaigns/:campaign_id', 'campaign'); so I could go either /campaign/x/details or /campaigns/x/details.

...but in the alias, this fails to provide the expected modelFor('campaign'). Not sure how to use this package for this at all.

rwjblue commented 4 years ago

Ultimately, I think this package should probably be deprecated.