diff --git a/docs/content/2.guide/14.extend-pages.md b/docs/content/2.guide/14.extend-pages.md new file mode 100644 index 000000000..e276dea4d --- /dev/null +++ b/docs/content/2.guide/14.extend-pages.md @@ -0,0 +1,54 @@ +# Extending pages + +Adding localized pages from a module. + +--- + +::alert{type="info"} +This is a workaround, support for extending pages with localization regardless of module registration order may be added in the future. +:: +::alert{type="warning"} +Your module has to registered before `@nuxtjs/i18n` to ensure localized routes are generated for the added pages. +:: + + +If you're a **module author** and want your module to add extra pages to your project, you can add these by using the `pages:extend` Nuxt hook. + +::code-group + ::code-block{label="Nuxt config" active} + ```ts {}[nuxt.config.ts] + import ExampleModule from './modules/example-module' + + export default defineNuxtConfig({ + modules: [ + ExampleModule, // Register module before `@nuxtjs/i18n` + '@nuxtjs/i18n', + ], + }) + ``` + :: + ::code-block{label="Module configuration"} + ```ts {}[modules/example-module/index.ts] + import { defineNuxtModule, resolve } from '@nuxt/kit' + + export default defineNuxtModule({ + setup(options, nuxt) { + const { resolve } = createResolver(import.meta.url); + + nuxt.hook('pages:extend', (pages) => { + pages.push({ + name: 'example-page', + path: '/example-page', + file: resolve(__dirname, './pages/example-page.vue'), + }); + }); + } + }) + ``` + :: +:: + + + + + diff --git a/docs/content/2.guide/14.migrating.md b/docs/content/2.guide/15.migrating.md similarity index 100% rename from docs/content/2.guide/14.migrating.md rename to docs/content/2.guide/15.migrating.md