mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(nuxt): enable router when app/router.options.ts
file is present (#8193)
This commit is contained in:
parent
d862a6bfdd
commit
b9d6f37dfd
@ -10,7 +10,7 @@ head.title: "Pages"
|
|||||||
Nuxt provides a file-based routing to create routes within your web application using [Vue Router](https://router.vuejs.org) under the hood.
|
Nuxt provides a file-based routing to create routes within your web application using [Vue Router](https://router.vuejs.org) under the hood.
|
||||||
|
|
||||||
::alert{type="info"}
|
::alert{type="info"}
|
||||||
This directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [app.vue](/guide/directory-structure/app), reducing your application's bundle size.
|
This directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [app.vue](/guide/directory-structure/app) (unless you set `pages: true` in `nuxt.config` or have a [`app/router.options.ts`](/guide/directory-structure/pages#router-options)), reducing your application's bundle size.
|
||||||
::
|
::
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
@ -18,8 +18,10 @@ export default defineNuxtModule({
|
|||||||
layer => resolve(layer.config.srcDir, layer.config.dir?.pages || 'pages')
|
layer => resolve(layer.config.srcDir, layer.config.dir?.pages || 'pages')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const isRouterOptionsPresent = nuxt.options._layers.some(layer => existsSync(resolve(layer.config.srcDir, 'app/router.options.ts')))
|
||||||
|
|
||||||
// Disable module (and use universal router) if pages dir do not exists or user has disabled it
|
// Disable module (and use universal router) if pages dir do not exists or user has disabled it
|
||||||
if (nuxt.options.pages === false || (nuxt.options.pages !== true && !pagesDirs.some(dir => existsSync(dir)))) {
|
if ((nuxt.options.pages === false || (nuxt.options.pages !== true && !pagesDirs.some(dir => existsSync(dir)))) && !isRouterOptionsPresent) {
|
||||||
addPlugin(resolve(distDir, 'app/plugins/router'))
|
addPlugin(resolve(distDir, 'app/plugins/router'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user