-
This is possible and easy in Nuxt 2. Depending on response from the server the module would dynamically add pages. If the server responded with an empty response then the pages would not be generated.
// page-foo/module.ts
import { defineNuxtModule, createResolver, extendPages } from '@nuxt/kit';
export default defineNuxtModule({
async setup() {
const resolver = createResolver(import.meta.url);
try {
const response = await apiFooRequest();
extendPages((pages) => {
pages.push(...Object.entries.map(([locale, path]) => ({
name: `foo__${locale}`,
path,
file: resolver.resolve('./pages/index.vue'),
})));
});
} catch {}
}
});
async function apiFooRequest() {
return {
en: '/foo',
lv: '/lv/foo',
ee: '/ee/foo'
};
} // nuxt.config.ts
export default defineNuxtConfig({
modules: [
'~/modules/page-foo/module',
],
}); |
Beta Was this translation helpful? Give feedback.
Answered by
simkuns
May 30, 2023
Replies: 1 comment
-
I was able to solve #discussion-5245536 by excluding pages containing patches/@nuxtjs+i18n+8.0.0-beta.12.patch diff --git a/node_modules/@nuxtjs/i18n/dist/module.mjs b/node_modules/@nuxtjs/i18n/dist/module.mjs
index 3ed0b53..1b75583 100644
--- a/node_modules/@nuxtjs/i18n/dist/module.mjs
+++ b/node_modules/@nuxtjs/i18n/dist/module.mjs
@@ -672,17 +672,27 @@ function setupPages(options, nuxt, additionalOptions = {
pagesDir,
pages: /* @__PURE__ */ new Map()
};
- analyzeNuxtPages(ctx, pages);
- const analyzer = (pageDirOverride) => analyzeNuxtPages(ctx, pages, pageDirOverride);
+ const unprefixedPages = [];
+ const alreadyPrefixedPages = [];
+ for (const page of pages) {
+ const { name } = page;
+ if (!name || !name.includes(options.routesNameSeparator)) {
+ unprefixedPages.push(page);
+ continue;
+ }
+ alreadyPrefixedPages.push(page);
+ }
+ analyzeNuxtPages(ctx, unprefixedPages);
+ const analyzer = (pageDirOverride) => analyzeNuxtPages(ctx, unprefixedPages, pageDirOverride);
mergeLayerPages(analyzer, nuxt);
- const localizedPages = localizeRoutes(pages, {
+ const localizedPages = localizeRoutes(unprefixedPages, {
...options,
includeUprefixedFallback,
localizeRoutesPrefixable,
optionsResolver: getRouteOptionsResolver(ctx, options)
});
pages.splice(0, pages.length);
- pages.unshift(...localizedPages);
+ pages.unshift(...alreadyPrefixedPages, ...localizedPages);
debug$7("... made pages", pages);
});
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
simkuns
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was able to solve #discussion-5245536 by excluding pages containing
routesNamesSuffix
fromanalyzeNuxtPages
.patches/@nuxtjs+i18n+8.0.0-beta.12.patch