f / vue-wait

Complex Loader and Progress Management for Vue/Vuex and Nuxt Applications
MIT License
2k stars 101 forks source link

Use vue-wait with vue-router and beforeRouteEnter #87

Open ahoiroman opened 4 years ago

ahoiroman commented 4 years ago

Hello everybody,

actually I'd like to use vue-wait with vue-router and beforeRouteEnter

If I'm doing something like

        beforeRouteEnter (to, _from, next) {
            const promises = [
                axios.get ('/api/user/1'),
            ];

            this.$wait.start('loading.users');

            axios.all (promises)
            .then (([userRes]) => {
                next ((vm) => {
                    vm.user = userRes.data.data;
                });
            });
        },

I am getting an error

TypeError: undefined is not an object (evaluating 'this.$wait')
beforeRouteEnter — ....js

So how could I solve this?

ThomasKuhlmann commented 4 years ago

this isn't available in the beforeRouteEnter guard, but that's a general Vue limitation - check out the Vue router docs, they talk about this and the solution in more detail.