mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 23:52:06 +00:00
docs(middleware): add navigateTo
options (#5044)
Co-authored-by: Daniel Roe <daniel@roe.dev>
This commit is contained in:
parent
53ea540ac0
commit
557c40c97f
@ -35,13 +35,14 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
|||||||
|
|
||||||
Nuxt provides two globally available helpers that can be returned directly from the middleware:
|
Nuxt provides two globally available helpers that can be returned directly from the middleware:
|
||||||
|
|
||||||
1. `navigateTo (route: string | Route)` - Redirects to the given route, within plugins or middleware. It can also be called directly on the client side to perform page navigation.
|
1. `navigateTo (route: string | Route, options: { redirectCode: number, replace: boolean )` - Redirects to the given route, within plugins or middleware. It can also be called directly to perform page navigation.
|
||||||
2. `abortNavigation (err?: string | Error)` - Aborts the navigation, with an optional error message.
|
2. `abortNavigation (err?: string | Error)` - Aborts the navigation, with an optional error message.
|
||||||
|
|
||||||
Unlike, navigation guards in [the vue-router docs](https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards), a third `next()` argument is not passed, and redirects or route cancellation is handled by returning a value from the middleware. Possible return values are:
|
Unlike navigation guards in [the vue-router docs](https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards), a third `next()` argument is not passed, and redirects or route cancellation is handled by returning a value from the middleware. Possible return values are:
|
||||||
|
|
||||||
* nothing - does not block navigation and will move to the next middleware function, if any, or complete the route navigation
|
* nothing - does not block navigation and will move to the next middleware function, if any, or complete the route navigation
|
||||||
* `navigateTo('/')` or `navigateTo({ path: '/' })` - redirects to the given path
|
* `navigateTo('/')` or `navigateTo({ path: '/' })` - redirects to the given path
|
||||||
|
* `navigateTo('/', { redirectCode: 302 })` - Redirects to the given path and will set the redirect code if the redirect happens on the server side (default: 301)
|
||||||
* `abortNavigation()` - stops the current navigation
|
* `abortNavigation()` - stops the current navigation
|
||||||
* `abortNavigation(error)` - rejects the current navigation with an error
|
* `abortNavigation(error)` - rejects the current navigation with an error
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user