A
A
aloky2018-12-08 19:59:15
Vue.js
aloky, 2018-12-08 19:59:15

Can't figure out router vue, can't figure out children?

There is such a path, I made it in the componenttransfers.vue

created() {this.$router.push({ path: '/transfers/new' })},
it helps only with the 1st press, and if you press it the 2nd time, it already tears off /transferssimply, but I need it to always /transfers/newbe
{
  path: '/transfers',
  name: 'transfers',
  component: transfers,
  children: [
    {
      path: 'new',
      name: 'new',
      component: transferFormWidget
    },
  ]
},

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Sedyshev, 2018-12-08
@aloky

You haven't written where you're clicking, but I'm assuming that the created hook is fired when the component is created.
vue-router tries to reuse components, so the second time created is not fired.
I don't think it's correct to write this, it's better like this:

{
  path: '/transfers',
  name: 'transfers',
  component: transfers,
  children: [
    {
      path: 'new',
      name: 'new',
      component: transferFormWidget
    },
    {
      path: '',
      redirect: 'new'
    }
  ]
},

And remove this.$router.push from the hook. In this case, if an empty child is passed for tranfers, vue-router will middle direct to transfers/new

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question