Vue3 Watching route not working on production

64 Views Asked by At

I have this bit of code. Im using it to watch if my project edit/create pages lead to certain pages, and if so I want to retain the data in them(not reset the project). otherwise every other page should reset the project in project create.

Array of excluded routes that should not trigger the deletion. On my local environment, this all works perfectly. If i run npm run production locally, it also works.

However on production environment on the live server, doesent work. I dont even get the two console logs in the watch function printed at all. Referring to these; console.log('accessed from a route where data should clear'); console.log('simply watching route, from', from.name, 'to', to.name);

I have no idea why, any help is greatly appreciated. Does watch $route not work in production or something?

  excludedRoutes: [
                'hsAssetTypeCreate',
                'hsAssetTypeEdit',
                'clientCreate',
                'contactCreate',
                'tradeContractorCreate',
                'userCreate',
                'formCreate',
                'projectCreate'
            ],
   watch: {
        $route(to, from) {
            console.log('accessed from a route where data should clear');
            console.log('simply watching route, from', from.name, 'to', to.name);
            if (this.excludedRoutes.includes(from.name) && !this.excludedRoutes.includes(to.name)) {
                console.log('data cleared',this.excludedRoutes.includes(from.name),this.excludedRoutes.includes(to.name));
                this.$store.commit('modals/setSelectedForms', {
                    formsModal: [],
                    workersModal: [],
                    assetsModal: [],
                    clientsModal: [],
                    tradeContractorsModal: []
                });
                //this.$store.commit('setProject', {});
                this.$store.dispatch('resetProject');
                this.$store.commit('modals/setunsavedChanges', false);
                this.$store.commit('modals/closeAll');
            }else{
                console.log('data shouldnt have been cleared');
            }
        },
}
0

There are 0 best solutions below