mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
docs: add defineNuxtRouteMiddleware
migration (#21718)
This commit is contained in:
parent
e58cfc81f0
commit
1ee704c184
@ -233,6 +233,28 @@ If you want to use the new Nuxt composables (such as `useNuxtApp` or `useRuntime
|
||||
Although a compatibility interface is provided via `nuxtApp.vueApp` you should avoid registering plugins, directives, mixins or components this way without adding your own logic to ensure they are not installed more than once, or this may cause a memory leak.
|
||||
::
|
||||
|
||||
## New Middleware Format (Optional)
|
||||
|
||||
You can now migrate to the Nuxt 3 middleware API, which is slightly different in format from Nuxt 2.
|
||||
|
||||
Middleware now take only two argument (`to`, `from`). You can find out more in [the docs](/docs/guide/directory-structure/middleware).
|
||||
|
||||
```js
|
||||
export default defineNuxtRouteMiddleware((to) => {
|
||||
if (to.path !== '/') {
|
||||
return navigateTo('/')
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
::alert{type=warning}
|
||||
Use of `defineNuxtRouteMiddleware` is not supported outside of the middleware directory.
|
||||
::
|
||||
|
||||
::alert{type=warning}
|
||||
Nuxt Bridge does not support `definePageMeta`.
|
||||
::
|
||||
|
||||
## New `useHead` (Optional)
|
||||
|
||||
Nuxt Bridge provides a new Nuxt 3 meta API that can be accessed with a new `useHead` composable.
|
||||
|
Loading…
Reference in New Issue
Block a user