You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can customize the error page by adding a `layouts/error.vue` file.
23
25
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).
25
27
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).
27
29
28
-
Example:
30
+
Example of a custom error page:
29
31
```html
30
32
<template>
31
-
<nuxt-container>
32
-
<div>My navigation bar here</div>
33
-
<nuxt/>
34
-
</nuxt-container>
33
+
<divclass="container">
34
+
<h1v-if="error.statusCode === 404">Page not found</h1>
35
+
<h1v-else>An error occured</h1>
36
+
<nuxt-linkto="/">Home page</nuxt-link>
37
+
</div>
35
38
</template>
39
+
40
+
<script>
41
+
exportdefault {
42
+
props: ['error']
43
+
}
44
+
</script>
36
45
```
37
46
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.*
39
54
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:
0 commit comments