Facing issue related to link generation through LinkTo helper

I am facing error for both that cases with the linkParam & without too. I have recently updated my app from v1.13.15 to v3.20.2. And errors are occurring only for search route links, detail pages links are rendering fine. Please help.

"Error: Assertion Failed: You attempted to generate a link for the "clients.owners.search" route, but did not pass the models required for generating its dynamic segments. Cannot convert undefined or null to object
    at assert (http://localhost:4200/assets/vendor.js:43478:15)
    at Class.computeLinkToComponentHref (http://localhost:4200/assets/vendor.js:12284:50)
    at http://localhost:4200/assets/vendor.js:22437:25
    at untrack (http://localhost:4200/assets/vendor.js:62608:7)
    at ComputedProperty.get (http://localhost:4200/assets/vendor.js:22436:32)
    at Class.CPGETTER_FUNCTION [as href] (http://localhost:4200/assets/vendor.js:21544:25)
    at getPossibleMandatoryProxyValue (http://localhost:4200/assets/vendor.js:21837:19)
    at _getProp (http://localhost:4200/assets/vendor.js:21902:17)
    at get (http://localhost:4200/assets/vendor.js:21888:55)
    at http://localhost:4200/assets/vendor.js:54096:34"

Template.hbs

{{#if quickLink.linkParam}}
      <LinkTo @route={{quickLink.linkUrl}} @model={{quickLink.linkParam}}>
        {{t quickLink.nameLocalizedKey}}
      </LinkTo>
    {{else}}
      <LinkTo @route={{quickLink.linkUrl}}>
        {{t quickLink.nameLocalizedKey}}
      </LinkTo>
    {{/if}}

Initializer-app-settings.js

OwnerSearch: {
        linkUrl: 'clients.owners.search',
        nameLocalizedKey: 'dashboard.button.ownerSearch',
        linkType: 'default'
      },

ActiveRandomPrograms: {
        linkUrl: 'drug-tests.programs.search',
        linkParam: 'randomProgram',
        nameLocalizedKey: 'dashboard.button.randomProgram',
        linkType: 'default'
      },

Router.js

this.route('clients', function () {
this.route('owners', function () {
      this.route('search');
    });
})

this.route('drug-tests', function () {
  this.route('programs', function () {
      this.route('search', {
        path: '/search/:searchType'
      });
    });
})

(I edited the formatting of the above post to add code fences so it’s readable.)

The stuff about “did not pass the models required” is honestly pretty confusing error handling from within Ember. I’m filing a bug about that right now.

Your real exception is the part that says “Cannot convert undefined or null to object”. We can’t see its corresponding stack trace here.

My suggestion is to put a breakpoint at the place where this exception is thrown, and manually inspect e, the underlying exception, to get its stack trace. Most likely it will point you to something like one of your Route’s serialize hooks throwing an exception.

I submitted a PR to make this error message better in Ember.

1 Like

I am getting this error because I have declared a local property “queryParams” in route clients/owners/search.js. For now, I have commented the declaration of the property. And I have to have to do the implementation as per the latest version regarding the “queryParams” which I’ll do it later.

Now, the links are rendering fine.