Plugin Options
Options accepted by the default Layouts() export.
interface UserOptions {
layoutsDirs?: string | string[]
extensions?: string[]
exclude?: string[]
defaultLayout?: string
importMode?: (name: string) => 'sync' | 'async'
inheritDefaultLayout?: boolean
dts?: boolean | string
}layoutsDirs
- Type:
string | string[] - Default:
'src/layouts' - Related:
exclude, Layout Names
Relative path to the layouts directory. Supports globs. All .vue files in this folder are imported async into the generated code.
Can also be an array of layout dirs:
Layouts({
layoutsDirs: ['src/layouts', 'src/admin-layouts'],
})Can use ** to support scenarios like module1/layouts and modules2/layouts:
Layouts({
layoutsDirs: 'src/**/layouts',
})Any files named __*__.vue are excluded. Additional exclusions go through exclude.
extensions
- Type:
string[] - Default:
['vue']
Valid file extensions for layout components.
Layouts({
extensions: ['vue'],
})exclude
- Type:
string[] - Default:
[] - Related:
layoutsDirs
List of path globs to exclude when resolving layouts.
Layouts({
exclude: ['**/components/**'],
})Files named __*__.vue are always excluded, regardless of this option.
defaultLayout
- Type:
string - Default:
'default' - Related: Layout Names
Normalized layout name to use when a route does not specify meta.layout.
The value is a layout name, not a filename. For example myDefault.vue is named my-default:
Layouts({
defaultLayout: 'my-default',
})fallbackLayout
- Type:
string - Default: the value of
defaultLayout - Related: Layout Names
Normalized layout name to render when a page asks for a layout that does not exist, for example a typo in meta.layout or in setPageLayout. A warning naming the missing layout is logged once per name.
Layouts({
fallbackLayout: 'blank',
})If the fallback layout does not exist either, the page renders without a layout and a second warning is logged once.
importMode
- Type:
(name: string) => 'sync' | 'async' - Default:
'sync'for SSG,'async'otherwise
Mode for importing layouts. The default is detected from the build: static site generation imports synchronously, everything else asynchronously.
Layouts({
importMode: name => (name === 'default' ? 'sync' : 'async'),
})inheritDefaultLayout
- Type:
boolean - Default:
true - Related: How it works
Whether nested routes should inherit the default layout from parent routes.
When false, if a child route has its own layout, the parent route won't use the default layout. This prevents double-wrapping layouts when child routes specify their own layout.
This option applies to Vue Router 5 file-based routes, which generate nested route structures with children arrays. It can only be set globally in the plugin configuration.
Layouts({
inheritDefaultLayout: false,
})dts
- Type:
boolean | string - Default:
false - Related: Typed Layouts
Generate a .d.ts that types layout names. true writes layouts.d.ts in the Vite root; a string is a path relative to the root. Add the file to your tsconfig.json include.