eslint-plugin-vue icon indicating copy to clipboard operation
eslint-plugin-vue copied to clipboard

New Rule: disallow using deprecated `next` argument in `NavigationGuard`

Open roydukkey opened this issue 11 months ago • 0 comments

Please describe what the rule should do:

The rule should warn/error when the next argument is used on Vue Router navigation gaurds.

What category should the rule belong to?

[ ] Enforces code style (layout) [ ] Warns about a potential error (problem) [x] Suggests an alternate way of doing something (suggestion) [x] Other: the feature is deprecated

Provide 2-3 code examples that this rule should warn about:

// BAD
router.beforeEach((to, from, next) => {
  if (to.name !== 'Login' && !isAuthenticated) {
    next({ name: 'Login' })
  } else {
    next()
  }
})
// GOOD
router.beforeEach((to) => {
  if (to.name !== 'Login' && !isAuthenticated) {
    return { name: 'Login' };
  }
})

Additional context

  • Alternative to #1457.
  • Docs: https://router.vuejs.org/guide/advanced/navigation-guards.html#Optional-third-argument-next

roydukkey avatar Mar 12 '24 15:03 roydukkey