[Vuejs]-Vue: beforeEach is not a function

9👍

You’ve capitalized Router, that’s the class name. What you want to do is add your .beforeEach() to the instance of the router. You’ll notice in the documentation that it’s always a lowercase router they’re adding the guards to.

Currently, you’re immediately exporting the instance from the module, so you’ll need to first add it to a variable when you create a new Router and then add your .beforeEach() clauses to it before finally exporting it.

const router = new Router({
  ...
})

router.beforeEach( ... )

export default router
👤Soviut

Leave a comment