single-spa / single-spa-vue

a single-spa plugin for vue.js applications
MIT License
182 stars 42 forks source link

Allow appOptions to resolve asynchronously #69

Closed Sergej-Popov closed 3 years ago

Sergej-Popov commented 3 years ago

What: This PR adds the ability to resolve app options asynchronously. Why: In some scenarios (e.g. multi-tenant applications) resolution of app options such as a router, i18n etc, requires loading configuration and resources asynchronously.

At the moment there are no asynchronous hooks except loadRootComponent which is insufficient.

Example:


const vueLifecycles = singleSpaVue({
  Vue,
  async appOptions () {
    const config = await loadConfiguration()

    const i18n = await  i18nFactory(config);
    const router = await  routerFactory(config);

    return {
      render: h => h(App),
      router,
      i18n
    }
  }
});

export const bootstrap = vueLifecycles.bootstrap;
export const mount = vueLifecycles.mount;
export const unmount = vueLifecycles.unmount;
joeldenning commented 3 years ago

I've created https://github.com/single-spa/single-spa.js.org/issues/403 to track documenting this feature.

joeldenning commented 3 years ago

This is released in https://github.com/single-spa/single-spa-vue/releases/tag/v2.2.0

Sergej-Popov commented 3 years ago

Thanks for releasing so quickly. Docs: https://github.com/single-spa/single-spa.js.org/pull/405