Skip to content

Commit 8fdd9c5

Browse files
NoelDeMartinposva
andauthored
docs: fix guard example (#3129)
* Update guard example to avoid stack overflow * Update docs/guide/advanced/navigation-guards.md Co-Authored-By: Eduardo San Martin Morote <[email protected]> * Use route name in next() call for consistency Co-authored-by: Eduardo San Martin Morote <[email protected]>
1 parent 8f831f2 commit 8fdd9c5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/guide/advanced/navigation-guards.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Every guard function receives three arguments:
3939
```js
4040
// BAD
4141
router.beforeEach((to, from, next) => {
42-
if (!isAuthenticated) next('/login')
42+
if (to.name !== 'Login' && !isAuthenticated) next({ name: 'Login' })
4343
// if the user is not authenticated, `next` is called twice
4444
next()
4545
})
@@ -48,7 +48,7 @@ router.beforeEach((to, from, next) => {
4848
```js
4949
// GOOD
5050
router.beforeEach((to, from, next) => {
51-
if (!isAuthenticated) next('/login')
51+
if (to.name !== 'Login' && !isAuthenticated) next({ name: 'Login' })
5252
else next()
5353
})
5454
```

0 commit comments

Comments
 (0)