[Vuejs]-Vue js beforeRouteEnter

2👍

  • you can’t use this in beforeRouteEnter function,because before the route updates, your component’s vm does not exist.
  • in consideration of you put role information in your vm, you can use next to get your vm:
beforeRouteEnter(to, from, next) {
  next(vm => {
    // put your logic here
    if (vm.role === 'Admin') {
    }
  })
}
  • actually,you should use the Global Router Guard ,and put your role information in global area,so that your can redirect your routing before your target component created
👤Kaicui

Leave a comment