S
S
Sergei Iamskoi2020-09-29 22:49:06
Vue.js
Sergei Iamskoi, 2020-09-29 22:49:06

Why doesn't router.push work?

It's simple, there is a button: and a method:
<a @click="exit()">Exit</a>

methods: {
    exit () {
      localStorage.removeItem('token');
      this.$router.push({ path: '/login' }).catch(
        err => console.log('catch: ', err)
      );
    }
}


Tried these variations:
push({ path: '/login' })
push({ name: 'Login' })
push('Login')
push('/login')

Spits 'catch: undefined' error in console
Routers:
const router = new Router({
  base: '/',
  mode: 'history',
  routes: [
  {
      path: '/',
      component: Layout,
      children: [
        {
          name: 'Login',
          path: 'login',
          component: Login,
        },
        ...
      ]
   }]
})


What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-09-29
@yarkov Vue.js

Why is there catch ? Did you open the documentation at all?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question