nativescript-vue-router-extended
Version:
NativeScript Vue Router Extended for NativeScript Vue hybrid Apps.
27 lines • 829 B
JavaScript
export class RouterDispatcherService {
constructor(store) {
this.store = store;
}
dispatchFromMeta(meta) {
if (!meta || !this.store) {
return false;
}
Object.keys(meta).forEach((key) => {
this.dispatch(key, meta[key]);
});
return true;
}
dispatch(type, payload) {
return this.store.dispatch(type, payload);
}
}
export const registerActionDispatcher = (router, store) => {
const dispatcherService = new RouterDispatcherService(store);
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