Skip to content

Commit ccc960d

Browse files
committed
Add layout documentation
1 parent 91a51d4 commit ccc960d

File tree

1 file changed

+49
-17
lines changed

1 file changed

+49
-17
lines changed

en/guide/layouts.md

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,69 @@ title: Layouts
44

55
# Layouts
66

7-
> Nuxt.js allows you to extend the main application by adding a `layouts/app.vue` file
7+
> Nuxt.js allows you to extend the main layout or create custom layout by adding them in the `layouts/` directory
88
9-
## The default app
9+
## layouts/default.vue
1010

11-
The default source code of the main app is:
11+
You can extend the main layout by adding a `layouts/default.vue` file.
12+
13+
*Make sure to add the `<nuxt>` component when creating a layout to display the page component.*
14+
15+
The default layout source code is:
1216
```html
1317
<template>
14-
<nuxt-container>
15-
<nuxt/>
16-
</nuxt-container>
18+
<nuxt/>
1719
</template>
1820
```
1921

20-
## The `layouts/app.vue` file
22+
## layouts/error.vue
2123

22-
### 🎬 [Example video](https://www.youtube.com/watch?v=wBhia7uBxDA)
24+
You can customize the error page by adding a `layouts/error.vue` file.
2325

24-
You have to make sure to add the `<nuxt-container>` and `<nuxt>` components when extending the app.
26+
This layout is special since your should not include `<nuxt/>` inside its template, see this layout as a component displayed when an error occurs (404, 500, etc).
2527

26-
It is important that the code you add stays inside `<nuxt-container>`.
28+
The default error page source code is [available on Github](https://github.com/nuxt/nuxt.js/blob/master/lib/app/components/nuxt-error.vue).
2729

28-
Example:
30+
Example of a custom error page:
2931
```html
3032
<template>
31-
<nuxt-container>
32-
<div>My navigation bar here</div>
33-
<nuxt/>
34-
</nuxt-container>
33+
<div class="container">
34+
<h1 v-if="error.statusCode === 404">Page not found</h1>
35+
<h1 v-else>An error occured</h1>
36+
<nuxt-link to="/">Home page</nuxt-link>
37+
</div>
3538
</template>
39+
40+
<script>
41+
export default {
42+
props: ['error']
43+
}
44+
</script>
3645
```
3746

38-
## Error Layout
47+
## layouts/*.vue
48+
49+
See the [demonstration video](https://www.youtube.com/watch?v=YOKnSTp7d38).
50+
51+
Every file (*first level*) in the `layouts/` directory will create a custom layout accessible with the `layout` property in the page component.
52+
53+
*Make sure to add the `<nuxt>` component when creating a layout to display the page component.*
3954

40-
> Todo + add sublinks in menu.json
55+
Example of `layouts/blog.vue`:
56+
```html
57+
<template>
58+
<div>
59+
<div>My blog navigation bar here</div>
60+
<nuxt/>
61+
</div>
62+
</template>
63+
```
64+
65+
And then in `pages/posts.vue` I can tell Nuxt.js to use this custom layout:
66+
```html
67+
<script>
68+
export default {
69+
layout: 'blog'
70+
}
71+
</script>
72+
```

0 commit comments

Comments
 (0)