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

docs: add extend pages page #1903

Merged
merged 1 commit into from
Mar 2, 2023
Merged
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
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'),
});
});
}
})
```
::
::