Open vsqla opened 10 months ago
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__
so, how to force prefetch to work on every page?
routes:
MainLayout:
Store:
quasar.conf:
Excepted: all generated pages have initial data; Result: only one of the generated pages have non empty __INITIAL_STATE__