fix(nuxt): enable router when app/router.options.ts file is present (#8193)

This commit is contained in:
Benicio Cardozo 2022-10-15 08:04:06 -03:00 committed by GitHub
parent d862a6bfdd
commit b9d6f37dfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -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

View File

@ -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
} }