Skip to content

Commit

Permalink
docs: add extend pages page (#1903)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede authored Mar 2, 2023
1 parent 0b589d2 commit 029c634
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions docs/content/2.guide/14.extend-pages.md
Original file line number Diff line number Diff line change
@@ -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'),
});
});
}
})
```
::
::





File renamed without changes.

0 comments on commit 029c634

Please sign in to comment.