-
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b589d2
commit 029c634
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.