Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4870

Why the route will run twice when i transition back from another route?

$
0
0

Currently i having a route which is use to findAll the record from a model. But the result comeback as an array so in the template I used {{#each}} to loop them. Originally it comeback two records in the array which is the correct behavior. But whenever i try to transition to another route and transition back it will comeback 4 records which is duplicate. It will multiple each time when i try to transition back. I’m not sure which part is missing or having mistake that cause that behavior. Or variable must be destroy when leave the route?

Route

 @task(function* (){
      try {
        let companyList = yield this.store.findAll('list-company');

        return {
            companyList: companyList,
        }
      } catch (e) {
        this.intermediateTransitionTo('error', e);
        throw (e);
      }
  
      }).restartable() loadModelTask;
  
    model() {
      try {
        return this.loadModelTask.perform();
      } catch (e) {
        throw (e);
      }
    }

    setupController(controller, model) {
        this._super(controller, model);
        controller.set('companyList', model.companyList);
    
    }

Template

{{#if loadModelTask.isRunning}}
      ////code
{{else}}
  {{#each companyList as |comp|}}
     ////code
  {{/each}}
{{/if}}

Before transition when the route is called

Screenshot from 2021-08-18 14-18-55

After transition back from other page, the record is duplicated

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4870

Trending Articles