Skip to content

Commit

Permalink
docs: ensure we guard all navigateTo examples (nuxt#20678)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored May 4, 2023
1 parent 30132f3 commit 8c75961
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docs/2.guide/2.directory-structure/1.middleware.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 8c75961

Please sign in to comment.