Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: ensure we guard all navigateTo examples #20678

Merged
merged 1 commit into from May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/2.guide/2.directory-structure/1.middleware.md
Expand Up @@ -30,7 +30,9 @@ export default defineNuxtRouteMiddleware((to, from) => {
if (to.params.id === '1') {
return abortNavigation()
}
return navigateTo('/')
if (to.path !== '/') {
return navigateTo('/')
}
})
```

Expand Down
4 changes: 3 additions & 1 deletion docs/3.api/3.utils/abort-navigation.md
Expand Up @@ -36,7 +36,9 @@ export default defineNuxtRouteMiddleware((to, from) => {
return abortNavigation()
}

return navigateTo('/edit-post')
if (to.path !== '/edit-post') {
return navigateTo('/edit-post')
}
})
```

Expand Down
4 changes: 3 additions & 1 deletion docs/3.api/3.utils/define-nuxt-route-middleware.md
Expand Up @@ -56,7 +56,9 @@ export default defineNuxtRouteMiddleware((to, from) => {
return navigateTo('/login')
}

return navigateTo('/dashboard')
if (to.path !== '/dashboard') {
return navigateTo('/dashboard')
}
})
```

Expand Down
4 changes: 3 additions & 1 deletion docs/3.api/3.utils/define-page-meta.md
Expand Up @@ -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')
}
}
],

Expand Down
6 changes: 4 additions & 2 deletions docs/3.api/3.utils/navigate-to.md
Expand Up @@ -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 })
}
})
```

Expand Down