Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

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

Merged
merged 5 commits into from Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/2.guide/2.directory-structure/1.pages.md
Expand Up @@ -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.

::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 provide an [`router.options.ts`](/guide/directory-structure/pages#router-options), reducing your application's bundle size.
vencho-mdp marked this conversation as resolved.
Show resolved Hide resolved
::

## Usage
Expand Down
4 changes: 3 additions & 1 deletion packages/nuxt/src/pages/module.ts
Expand Up @@ -18,8 +18,10 @@ export default defineNuxtModule({
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
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'))
return
}
Expand Down