From 8fdd9c527a5e445de00e0fdd378e42c7a26bd7d7 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Sun, 23 Feb 2020 22:52:35 +0100 Subject: [PATCH] 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 * Use route name in next() call for consistency Co-authored-by: Eduardo San Martin Morote --- docs/guide/advanced/navigation-guards.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guide/advanced/navigation-guards.md b/docs/guide/advanced/navigation-guards.md index 61d9bf13c..3a99e74cf 100644 --- a/docs/guide/advanced/navigation-guards.md +++ b/docs/guide/advanced/navigation-guards.md @@ -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() }) @@ -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() }) ```