mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
docs: ensure we guard all navigateTo
examples (#20678)
This commit is contained in:
parent
30132f3603
commit
8c75961f74
@ -30,7 +30,9 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
||||
if (to.params.id === '1') {
|
||||
return abortNavigation()
|
||||
}
|
||||
return navigateTo('/')
|
||||
if (to.path !== '/') {
|
||||
return navigateTo('/')
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -36,7 +36,9 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
||||
return abortNavigation()
|
||||
}
|
||||
|
||||
return navigateTo('/edit-post')
|
||||
if (to.path !== '/edit-post') {
|
||||
return navigateTo('/edit-post')
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -56,7 +56,9 @@ export default defineNuxtRouteMiddleware((to, from) => {
|
||||
return navigateTo('/login')
|
||||
}
|
||||
|
||||
return navigateTo('/dashboard')
|
||||
if (to.path !== '/dashboard') {
|
||||
return navigateTo('/dashboard')
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -144,7 +144,9 @@ The example below shows how the middleware can be defined using a `function` dir
|
||||
return navigateTo('/login')
|
||||
}
|
||||
|
||||
return navigateTo('/checkout')
|
||||
if (to.path !== '/checkout') {
|
||||
return navigateTo('/checkout')
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
|
@ -96,8 +96,10 @@ await navigateTo({
|
||||
|
||||
```ts
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
// setting the redirect code to '301 Moved Permanently'
|
||||
return navigateTo('/search', { redirectCode: 301 })
|
||||
if (to.path !== '/search') {
|
||||
// setting the redirect code to '301 Moved Permanently'
|
||||
return navigateTo('/search', { redirectCode: 301 })
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user