Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arnebit opened this issue May 8, 2018 · 2 comments

Comments

@arnebit
Copy link

arnebit commented May 8, 2018

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
Copy link

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
Copy link
Collaborator

rwjblue commented May 27, 2020

Ultimately, I think this package should probably be deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants