O
O
ocatoll2018-03-07 06:39:22
Ember.js
ocatoll, 2018-03-07 06:39:22

Why does an error occur when navigating from a nested route to another element of this route?

There is a /property/show.js route

import Ember from 'ember';
const {inject} = Ember;
export default Ember.Route.extend({
  model(params) {
    let store = this.get('store');
    let p = store.findRecord('property', params.property_id, {reload: true});
    return p;
  },
  actions: {
    reloadModel: function () {
      this.refresh();
    },
    back: function (type) {
      this.transitionTo('property/' + type);
    },
  }
});

There is a corresponding template that displays information about the object and there is a list of similar objects that you can go to, conditionally like this
{{#link-to 'property.show' similar.id}}
{{similar.id}}
{{/ link-to}}
The problem is that when I go to the object card via a direct link, everything is fine - the correct model is loaded and all that. But when I try to switch from a card to another card by clicking on a link generated via link-to, only the address in the browser line changes, and in the chrome console I get
VM1596 vendor.js:58445 Uncaught TypeError: Cannot read property 'insertBefore' of null
at Object.insertBefore (VM1596 vendor.js:58445)
at MorphList$insertBeforeMorph [as insertBeforeMorph] (VM1596 vendor.js:58362)
at Object.yieldItem (VM1596 vendor.js:55659)
at VM1596 vendor.js:20579
at Class.forEach (VM1596 vendor.js:45489)
at forEach (VM1596 vendor.js:20587)
at Child.eachHelper [as helper] ( VM1596 vendor.js:20576)
at Child.compute (VM1596 vendor.js:25455)
at Child.value (VM1596 vendor.js:26080)
at Object.invokeHelper (VM1596 vendor.js:21604
) what could be my problem

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
ocatoll, 2018-03-07
@ocatoll

Found the reason. In my case, the problem is ember-cli-slick, which breaks js. Why and what to do is not yet clear.

S
Stanislav Romanov, 2018-03-07
@Kaer_Morchen

similar.id is everything ok?
Check the variable in the template:

{{log similar.id}}
{{#link-to 'property.show' similar.id}} 
{{similar.id}}
{{/link-to}}

Show this part of the router and this route in its entirety

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question