I'm setting up a microfrontends architecture with single-spa, vue3 and pinia.
I'm having some issue whereby I'm defining a store in a utiity microapp which gets imported in all other microapps. In a microapp I'm then creating a pinia as a plugin and setting app.use(piniaPlugin). Then in the microapp component I'm calling the useExportedStore() but this throws a pinia not found error.
Here some code snippets.
single-spa-utils
import { defineStore } from 'pinia';
export const useGlobalState = defineStore('GlobalState', {
id: 'GlobalState',
state: () => ({
currentRoute: '/',
}),
getters: {},
actions: {},
});
single-spa-microapp/main.js
import { globalStorePlugin } from "@/plugins/storesPlugins";
const vueLifecycles = singleSpaVue({
createApp,
appOptions: {
render() {
return h(App, {});
},
},
handleInstance: (app) => {
console.log('>>> HANDLING INSTANCE APP')
app.use(globalStorePlugin)
},
});
single-spa-microapp/storePlugins.js
import { globalStore } from "@/stores/globalStore";
export const globalStorePlugin = {
install: app => {
console.log('globalStorePlugin :: installing globalStore pinia')
app.use(globalStore);
}
}
single-spa-microapp/component.vue
import { useGlobalState } from "@smart-inventory/smart-inventory-glob-lib";
const globalState = useGlobalState();