UNPKG

nativescript-vue-router-extended

Version:

NativeScript Vue Router Extended for NativeScript Vue hybrid Apps.

31 lines 947 B
export class RouterDispatcherService { constructor(vm) { this.vm = vm; } dispatchFromMeta(meta) { if (!meta || !this.vm) { return false; } if (!this.vm.$store) { console.error('META DISPATCHER', 'Store not found'); return false; } Object.keys(meta).forEach((key) => { this.dispatch(key, meta[key]); }); return true; } dispatch(type, payload) { return this.vm.$store.dispatch(type, payload); } } export const registerActionDispatcher = (router, vm) => { const dispatcherService = new RouterDispatcherService(vm); router.beforeResolve((to, _from, _next) => { const route = router.getRoute(to); if (route && route.meta && route.meta.store) { dispatcherService.dispatchFromMeta(route.meta.store); } }); }; //# sourceMappingURL=router-dispatcher-service.js.map