docs: ensure we guard all navigateTo examples (#20678)

This commit is contained in:
Daniel Roe 2023-05-04 15:08:07 +01:00 committed by GitHub
parent 30132f3603
commit 8c75961f74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 6 deletions

View File

@ -30,7 +30,9 @@ export default defineNuxtRouteMiddleware((to, from) => {
if (to.params.id === '1') {
return abortNavigation()
}
return navigateTo('/')
if (to.path !== '/') {
return navigateTo('/')
}
})
```

View File

@ -36,7 +36,9 @@ export default defineNuxtRouteMiddleware((to, from) => {
return abortNavigation()
}
return navigateTo('/edit-post')
if (to.path !== '/edit-post') {
return navigateTo('/edit-post')
}
})
```

View File

@ -56,7 +56,9 @@ export default defineNuxtRouteMiddleware((to, from) => {
return navigateTo('/login')
}
return navigateTo('/dashboard')
if (to.path !== '/dashboard') {
return navigateTo('/dashboard')
}
})
```

View File

@ -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')
}
}
],

View File

@ -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 })
}
})
```