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

fix dynamic routes prerender #87

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ofetch } from 'ofetch';

export const getDynamicUserRoutes = async () => {
const response = await ofetch('https://dev-nuxt-auth.a.kuroco.app/rcms-api/1/member/list');
return response.list.flatMap((user) => [`/member/detail/${user.member_id}`, `/ja/member/detail/${user.member_id}`]);
};

export const getDynamicContentRoutes = async () => {
const response = await ofetch('https://dev-nuxt-auth.a.kuroco.app/rcms-api/1/content/list');
return response.list.flatMap((user) => [`/topics_detail/${user.topics_id}`, `/ja/topics_detail/${user.topics_id}`]);
};
25 changes: 20 additions & 5 deletions nuxt.config.ts → nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify';
export default defineNuxtConfig({
import { getDynamicUserRoutes, getDynamicContentRoutes } from './api';

export default {
runtimeConfig: {
public: {
kurocoApiDomain: 'https://dev-nuxt-auth.a.kuroco.app'
}
},

// generate: {
// routes: ['/member/detail/1', '/member/detail/2', '/member/detail/3']
// },

hooks: {
async 'nitro:config'(nitroConfig) {
if (nitroConfig.dev) {
return;
}
const dynamicUserRoutes = await getDynamicUserRoutes();
const dynamicContentRoutes = await getDynamicContentRoutes();
nitroConfig.prerender.routes.push(...dynamicUserRoutes, ...dynamicContentRoutes);
}
},

app: {
head: {
title: 'Nuxt Auth',
Expand All @@ -28,9 +45,7 @@ export default defineNuxtConfig({
},
{ name: 'robots', content: 'index' }
],
link: [
{ rel: 'icon', type: 'image/svg+xml', href: '/icon_kuroco.svg' },
]
link: [{ rel: 'icon', type: 'image/svg+xml', href: '/icon_kuroco.svg' }]
}
},

Expand Down Expand Up @@ -90,4 +105,4 @@ export default defineNuxtConfig({
}
}
}
});
};
Loading