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

feat(nuxt): define a custom root element inside app.config #8604

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
12 changes: 12 additions & 0 deletions docs/content/2.guide/2.directory-structure/3.app.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ declare module '@nuxt/schema' {
// It is always important to ensure you import/export something when augmenting a type
export {}
```

## Defining Custom Root Element

By default, Nuxt will mount your app inside a `#__nuxt` container. You may choose to customize the root element by defining another selector in your app config.

**Example:**

```ts [app.config.ts]
export default defineAppConfig({
el: '#some-other-container'
})
```
5 changes: 4 additions & 1 deletion packages/nuxt/src/app/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import _plugins from '#build/plugins'
import RootComponent from '#build/root-component.mjs'
// @ts-ignore
import AppComponent from '#build/app-component.mjs'
// @ts-ignore
import appConfig from '#build/app.config.mjs'

if (!globalThis.$fetch) {
// @ts-ignore
Expand Down Expand Up @@ -68,7 +70,8 @@ if (process.client) {
try {
await nuxt.hooks.callHook('app:created', vueApp)
await nuxt.hooks.callHook('app:beforeMount', vueApp)
vueApp.mount('#__nuxt')
const el = appConfig.el ?? '#__nuxt'
vueApp.mount(el)
await nuxt.hooks.callHook('app:mounted', vueApp)
await nextTick()
} catch (err) {
Expand Down