Questions surrounding Vue.js
Combine data fetch before navigation with keep-alive routesSeptember 3, 2018 at 1:39pm
I'm currently trying out the async data fetching before navigation approach described in the router docs here: https://router.vuejs.org/guide/advanced/data-fetching.html#fetching-before-navigation
That's working out quite well. However, I would also like to combine that approach with keeping alive routes (https://vuejs.org/v2/api/#keep-alive), so I don't have to fetch the same data every time I go back to an already rendered route. But these two approaches apparently don't cooperate very well. Now, data is fetched every time I navigate back to the route, even though it is being kept alive. Is there some sane way to avoid refetching data using the beforeRouteEnter method?
September 4, 2018 at 4:55am
September 12, 2018 at 6:36pm
September 13, 2018 at 12:50pm
I solved it in a similar way to what @ghapsara suggests, however I would like to avoid Vuex. I just created a global object on the Vue object, that keeps track which routes that have been loaded and check against that when reentering the route.