Skip to content

Commit

Permalink
docs: fix guard example (#3129)
Browse files Browse the repository at this point in the history
* Update guard example to avoid stack overflow

* Update docs/guide/advanced/navigation-guards.md

Co-Authored-By: Eduardo San Martin Morote <posva@users.noreply.github.com>

* Use route name in next() call for consistency

Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
  • Loading branch information
NoelDeMartin and posva committed Feb 23, 2020
1 parent 8f831f2 commit 8fdd9c5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/guide/advanced/navigation-guards.md
Expand Up @@ -39,7 +39,7 @@ Every guard function receives three arguments:
```js
// BAD
router.beforeEach((to, from, next) => {
if (!isAuthenticated) next('/login')
if (to.name !== 'Login' && !isAuthenticated) next({ name: 'Login' })
// if the user is not authenticated, `next` is called twice
next()
})
Expand All @@ -48,7 +48,7 @@ router.beforeEach((to, from, next) => {
```js
// GOOD
router.beforeEach((to, from, next) => {
if (!isAuthenticated) next('/login')
if (to.name !== 'Login' && !isAuthenticated) next({ name: 'Login' })
else next()
})
```
Expand Down

0 comments on commit 8fdd9c5

Please sign in to comment.