Ember.js: ember 2.10 undefined route dynamic segment no longer working.

Created on 30 Nov 2016  ·  22Comments  ·  Source: emberjs/ember.js

This looks more like a unsupported feature than a bug but I thought I would log it.

When upgrading from 2.9.1 to 2.10 I ran into the following exception.

"Assertion Failed: You attempted to define a `{{link-to "timecards"}}` but did not pass the parameters required for generating its dynamic segments. You must provide param `login` to `generate`."
#app/router.js
this.route('timecards', {path: '/timecards/:login'}, function() {
  this.route('index', { path: '/' });
  this.route('timecard-day', {path: '/day/:date'});
  this.route('pay-period', {path: '/pay-period/:date'});
});

#app/routes/timecards.js #model hook
model(params) {    
  let login = params.login || this.get('currentUser.login');
  return this.store.peekAll('user').findBy('login', login);
}

It was quite handy to use a optional dynamic segment on the parent route to load a default user model rather than having to load it for each individual child routes.

Ember 2.10 Inactive Needs Bug Verification Needs Submitter Response

Most helpful comment

This is blocking 2.10 and 2.11 for us. Happy to attempt a fix if someone can confirm this is a regression.

All 22 comments

I'm fairly sure you can still do this by passing undefined and implementing a custom serialize hook.

The error message added here is a pretty big win for folks in general, and I'd prefer to keep it around if possible...

@rwjblue passing undefined to the link-to helper throws this warning: This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid.

I had also issues with:

{{link-to 'projects.project.tasks' project}}
  this.route('projects', function() {
    this.route('project', { path: ':id' }, function() {
      this.route('tasks');
    });
  });

The Ember error told about undefined id.
The quick fix for that was to change :id in router to :project_id

I think that it's not real fix and it deserves to be qualified as a bug. Otherwise, there was no information about changing router behavior.

@Exelord that is unrelated to the originally described bug, and not a bug. We specifically document that the default implementation requires :modelname_id to work out of the box. If you are using a custom field, you will have to reimplement serialize/deserialize in the respective route.

@Exelord (as a sidenote, not directly related to this issue)... I'm not sure if this is documented or not but I don't think you can use the same identifier for a dynamic segment more than once in the router. So I'd avoid using ":id", and also avoid using ":modelname_id" more than once. (e.g. if needed again maybe use ":newmodelname_id", just something different)

@rwjblue @sly7-7 so it appears there is not a clean work-around for this issue, correct?

@arenoir can you make an ember-twiddle reproduction of this issue, it sounds like a bug. Having a repo of the issue will help diagnose the issue and also provide the verification of the bug.

@locks @pixelhandler
You have a right, guys. Thanks for help and explanation. But indeed it was working before 2.10.
I guess now, it was a bug or unexpected behavior.

@pixelhandler okay here is a twiddle.

:point_up: looks like a good reproduction. that label can be removed

I'm confused as to if this is to be regarded a regression or if I should fix in application.

This is blocking 2.10 and 2.11 for us. Happy to attempt a fix if someone can confirm this is a regression.

Same problem for me as described by @arenoir

Running into this same issue today 👎

@jakeleboeuf I was having the same issue and upgrading to 2.13.1 fixed it. Which version do you have?

[EDIT]
It's 2AM here and my brain is almost gone to deep space. I just realized I tested it wrong. It's still continuing...

In case anyone runs into this issue, could possibly be this:

import Controller from 'ember';
import { alias } from 'ember-computed';

export default Controller.extend({
  deployments: alias('model')
});

Note that I am importing Contoller incorrectly. It should be import Controller from 'ember-controller';. This is if you are using ember-cli-shims, which is what my current project is using. I was lost on this for about an hour before I gave up, came back and saw clearly what I was doing wrong.

Long shot here, but I ran into this issue when accidentally overriding the native Object with Ember's Object class via something like:

const { Object } = Ember;

This was causing my model hook (where Object.create is called) to fail and, for some reason, the exception thrown mentioned dynamic segments not being present. I think this is similar to what @alvincrespo mentions in his comment above.

@lrdiv yeah, I think this happening with me to.

Assertion Failed: You attempted to define a `{{link-to "control.templates.show"}}` but did not pass the parameters required for generating its dynamic segments. _ember.default.extend is not a function

@brunowego Yeah that's the same error I was getting. In our case it seems that this is more of a misleading exception than an actual bug.

@lrdiv this was also happening to me, good catch! :v:

What I was doing was to destructure Ember and precisely override the native Object with what was otherwise an Ember.Object. So I changed the name into something like const EmberObject = Ember.Object in the declaration and usage and all went the right way. I wouldn't call it a bug-bug either, so I agree with you on pretty much everything you wrote above :stuck_out_tongue_winking_eye:

@Exelord @acorncom @alvincrespo @arenoir @asvny @bjornharrtell @brunowego @carlbennettnz @dustinfarris @jakeleboeuf @locks @lrdiv @nightsh @rwjblue @sly7-7 @tarikozket is this still an issue, perhaps we should close or create a new reproduction of this, what do you think?

Closing for now, feel free to re-open if you can reproduce in the current release of Ember.

Was this page helpful?
0 / 5 - 0 ratings