JSFiddle - React, Tailwind, and code Playground

by darkylmnx

JavaScript

router.beforeResolve((to, from, next) => {
  // console.log(store, to.name);
  let done = 0;
  const route = to;
  const nextIfDone = () => {
    done++;

    if (done === to.matched.length) {
      next();
    }
  };

  to.matched.forEach((component) => {
    const { asyncData, mixins } = component.components.default;

    if (!asyncData) {
      nextIfDone();

      return;
    }

    Promise.resolve()
      .then(() => asyncData({
        router, route, store, errorHandlers,
      }))
      .then((data) => {
        console.log(data, mixins);
        if (isPlainObject(data)) {
          console.log('isPlainObject');

          const finalMixins = mixins || [];
          finalMixins.push({ data: () => data, created() { console.log('router mixin'); } });
          component.components.default.mixins = finalMixins;
        }

        nextIfDone();
      });
  });
});