docs: add warning about redirect check (#20680)

This commit is contained in:
Miachel Brevard 2023-06-12 11:45:53 +03:00 committed by GitHub
parent 05a8c2d955
commit 4ac4dfda15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -30,6 +30,9 @@ export default defineNuxtRouteMiddleware((to, from) => {
if (to.params.id === '1') {
return abortNavigation()
}
// In a real app you would probably not redirect every route to `/`
// however it is important to check `to.path` before redirecting or you
// might get an infinite redirect loop
if (to.path !== '/') {
return navigateTo('/')
}

View File

@ -48,7 +48,7 @@ You can pass the error as a string:
```ts [middleware/auth.ts]
export default defineNuxtRouteMiddleware((to, from) => {
const auth = useState('auth')
const user = useState('user')
if (!user.value.isAuthorized) {
return abortNavigation('Insufficient permissions.')