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
Copy file name to clipboardExpand all lines: docs/1.getting-started/07.routing.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -135,7 +135,7 @@ definePageMeta({
135
135
136
136
Nuxt offers route validation via the`validate` property in[`definePageMeta()`](/docs/4.x/api/utils/define-page-meta) in each page you wish to validate.
137
137
138
-
The`validate` property accepts the`route` as an argument. You can return a boolean value to determine whether or not this is a valid route to be rendered with this page. If you return`false`, this will cause a 404 error. You can also directly return an object with`statusCode`/`statusMessage` to customize the error returned.
138
+
The`validate` property accepts the`route` as an argument. You can return a boolean value to determine whether or not this is a valid route to be rendered with this page. If you return`false`, this will cause a 404 error. You can also directly return an object with`status`/`statusText` to customize the error returned.
139
139
140
140
If you have a more complex use case, then you can use anonymous route middleware instead.
Youcancallthisfunction at any point on client-side, or (onserverside) directly within middleware, plugins or `setup()` functions. It will trigger a full-screen error page which you can clear with [`clearError`](/docs/4.x/getting-started/error-handling#clearerror).
Copy file name to clipboardExpand all lines: docs/3.guide/1.concepts/2.nuxt-lifecycle.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,7 @@ After this step, Nuxt calls the [`app:created`](/docs/4.x/api/advanced/hooks#app
54
54
After initializing plugins and before executing middleware, Nuxt calls the`validate` method if it is defined in the`definePageMeta` function. The`validate` method, which can be synchronous or asynchronous, is often used to validate dynamic route parameters.
55
55
56
56
- The`validate` function should return`true` if the parameters are valid.
57
-
- If validation fails, it should return`false` or an object containing a`statusCode` and/or`statusMessage` to terminate the request.
57
+
- If validation fails, it should return`false` or an object containing a`status` and/or`statusText` to terminate the request.
58
58
59
59
For more information, see the[Route Validation documentation](/docs/4.x/getting-started/routing#route-validation).
You can pass either a string or an object to the`createError` function. If you pass a string, it will be used as the error`message`, and the`statusCode` will default to`500`. If you pass an object, you can set multiple properties of the error, such as`statusCode`,`message`, and other error properties.
17
+
You can pass either a string or an object to the`createError` function. If you pass a string, it will be used as the error`message`, and the`status` will default to`500`. If you pass an object, you can set multiple properties of the error, such as`status`,`message`, and other error properties.
18
18
19
19
##In Vue App
20
20
@@ -30,7 +30,7 @@ If you throw an error created with `createError`:
30
30
const route = useRoute()
31
31
const { data } = await useFetch(`/api/movies/${route.params.slug}`)
32
32
if (!data.value) {
33
-
throw createError({statusCode: 404,statusMessage: 'Page Not Found' })
33
+
throw createError({status: 404,statusText: 'Page Not Found' })
34
34
}
35
35
</script>
36
36
```
@@ -44,12 +44,12 @@ Use `createError` to trigger error handling in server API routes.
44
44
```ts [server/api/error.ts]
45
45
exportdefaulteventHandler(()=> {
46
46
throwcreateError({
47
-
statusCode:404,
48
-
statusMessage:'Page Not Found',
47
+
status:404,
48
+
statusText:'Page Not Found',
49
49
})
50
50
})
51
51
```
52
52
53
-
In API routes, using`createError` by passing an object with a short`statusMessage` is recommended because it can be accessed on the client side. Otherwise, a`message` passed to`createError` on an API route will not propagate to the client. Alternatively, you can use the`data` property to pass data back to the client. In any case, always consider avoiding to put dynamic user input to the message to avoid potential security issues.
53
+
In API routes, using`createError` by passing an object with a short`statusText` is recommended because it can be accessed on the client side. Otherwise, a`message` passed to`createError` on an API route will not propagate to the client. Alternatively, you can use the`data` property to pass data back to the client. In any case, always consider avoiding to put dynamic user input to the message to avoid potential security issues.