prerender mosaic routes
This commit is contained in:
parent
a065a1328d
commit
afc6a7668e
3 changed files with 26 additions and 5 deletions
4
.env
4
.env
|
|
@ -1,5 +1,5 @@
|
|||
VITE_STRAPI_URL=http://localhost:1337
|
||||
VITE_STRAPI_API_TOKEN=7e379ac0df1d055e91f1add3c97947068f60dc943a208524c7e10201c9d66210d6dee3ab48155581892e2cabe7a285d12395ace15a1f982e68fe5078abce0aebb826ae7c701302aa932d638ec57cb10f71fee7971e0a2b87a7fdf8eeb848eea90fb97d45fc8af69e818d1d5a59dc79cbc24f0bd1830d78670b85775ad6e05c6b
|
||||
|
||||
# VITE_STRAPI_URL=https://cms.nicwands.com
|
||||
# VITE_STRAPI_API_TOKEN=5934fb84b89fdca49ef58e4f493381848289fcfb09a5664c5a61d4673a6b81b10bdf1d364fa250d185049c14487b7297758c3653dbf37390f567d6d08d559b4c40aaf4dc10730a60b98011d6dc0553f2bd633b373739579d579e39a162f67ca6d8f0e5c5adb3537a7e94b303d79c4cb7f3f877e39158e37e5bd6838596ee9afe
|
||||
VITE_STRAPI_URL=https://cms.nicwands.com
|
||||
VITE_STRAPI_API_TOKEN=5934fb84b89fdca49ef58e4f493381848289fcfb09a5664c5a61d4673a6b81b10bdf1d364fa250d185049c14487b7297758c3653dbf37390f567d6d08d559b4c40aaf4dc10730a60b98011d6dc0553f2bd633b373739579d579e39a162f67ca6d8f0e5c5adb3537a7e94b303d79c4cb7f3f877e39158e37e5bd6838596ee9afe
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
<div v-if="global" class="layout">
|
||||
<site-header :copy="headerCopy" :dl="headerDl" />
|
||||
|
||||
<mosaic-scroll :items="mosaicItems" />
|
||||
<client-only>
|
||||
<mosaic-scroll :items="mosaicItems" />
|
||||
</client-only>
|
||||
|
||||
<suspense>
|
||||
<router-view />
|
||||
|
|
|
|||
23
src/main.js
23
src/main.js
|
|
@ -2,9 +2,28 @@ import './styles/main.scss'
|
|||
import App from './App.vue'
|
||||
import { ViteSSG } from 'vite-ssg'
|
||||
import routes from './routes'
|
||||
import strapi from './plugins/strapi'
|
||||
import strapiPlugin from './plugins/strapi'
|
||||
import { strapi } from '@strapi/client'
|
||||
|
||||
export const createApp = ViteSSG(App, routes, ({ app }) => {
|
||||
// Plugins
|
||||
app.use(strapi)
|
||||
app.use(strapiPlugin)
|
||||
})
|
||||
|
||||
// Prerender mosaic item routes
|
||||
export async function includedRoutes(_, routes) {
|
||||
const client = strapi({
|
||||
baseURL: `${import.meta.env.VITE_STRAPI_URL}/api`,
|
||||
auth: import.meta.env.VITE_STRAPI_API_TOKEN,
|
||||
})
|
||||
|
||||
const response = await client.single('global').find({ pLevel: '5' })
|
||||
const global = response.data
|
||||
|
||||
const itemRoutes =
|
||||
global?.mosaic_items?.map((item) => `/${item.slug}`) ?? []
|
||||
|
||||
return routes.flatMap((route) => {
|
||||
return route.name === 'mosaic-item' ? itemRoutes : route.path
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue