Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty data on all pages except one, when routes uses same component #383

Open
vsqla opened this issue Jan 24, 2024 · 1 comment
Open

Empty data on all pages except one, when routes uses same component #383

vsqla opened this issue Jan 24, 2024 · 1 comment

Comments

@vsqla
Copy link

vsqla commented Jan 24, 2024

routes:

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: () => import('layouts/MainLayout.vue'),
    children: [
      {
        path: '',
        component: () => import('pages/DynamicPage.vue'),
        props: () => ({ path: 'main' }),
      },
      {
        path: ':path?',
        component: () => import('pages/DynamicPage.vue'),
        props: (route) => ({ path: route?.params?.path ?? 'main' }),
      },
    ],
  },

MainLayout:

defineOptions({
  async preFetch() {
    const store = usePagesStore();
    await store.getPages();
    return store.pages.length > 0;
  },
});

Store:

export const usePagesStore = defineStore('pages', () => {
  const { resolveClient } = useApolloClient();
  const client = resolveClient();
  const pages = ref([]);

  const getPages = async () => {
    const res = await client.query({ query: getAllPages });
    console.log('GET PAGES!', res.data.pages.data.length);
    pages.value = res.data?.pages?.data ?? pages.value;
  };
  return {
    getPages,
    pages,
  };
});

quasar.conf:

prefetch: true,
ssg: {
      routes: async () => {
        const res = await axios.get(`${process.env.API_URI}/pages`);
        return res.data.data.map(({ attributes }) => attributes.path ?? '');
      },
      shouldPrefetch: () => true,
      shouldPreload: () => true,
      // crawler: true,
    },

Excepted: all generated pages have initial data;
Result: only one of the generated pages have non empty INITIAL_STATE

@vsqla
Copy link
Author

vsqla commented Jan 24, 2024

so, how to force prefetch to work on every page?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant