Search code examples
javascriptshopwareshopware6

Shopware 6: Reload a route after saving function using the Administration


I want to reload the route "sw.vehicles.list" after saving the entity vehicles. How can I do that ? I have used window.reload() but it doesn't work ! Could you help me please ?

methods: {
        async onStartProcess(e) {

            this.isLoading = true;
 
            this.sw_vehicles = this.repository.create(Shopware.Context.api);
                            
            if(data[i]['name']) this.sw_vehicles.vehicleName= data[i]['name'];
            if(data[i]['type']) this.sw_vehicles.vehicleType = data[i]['type'];
        
            this.repository.save(this.sw_vehicles, Shopware.Context.api).then(() => {
                        this.isLoading = false;
                        this.processSuccess = true;
                        this.$router.push({ name: 'sw.vehicles.list' });
                                
                        // reload the page "sw.vehicles.list"
               }).catch((exception) => {
                        this.isLoading = false;
                        this.createNotificationError({ 
                            title: this.$t('sw-vehicles.import.errorTitle'),
                            message: exception
                        });
              });
             }                    
            }                  
          } 
        },

        saveFinish(e) {
            this.processSuccess = false;
        },
}

Solution

  • Ideally you wouldn't want to reload the entire page when using a reactive framework, but still this should to the trick:

    window.location.reload(true)
    

    The boolean argument is for Firefox only to break the cache.