Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Params field is empty in $router.push

Consider this:

this.$root.$router.push({
    path: '/dashboard', 
    params: { errors: 'error' }, 
    query: { test: 'test' }
})

I use this in my component to redirect to another URL, and some error has occured. The problem is that when I want to access params field in dashboard component, it's empty. The query field works well. I'm trying to access it by this.$route.params.errors.

like image 564
Jozef Cipa Avatar asked Nov 18 '16 15:11

Jozef Cipa


2 Answers

You can use params only with named paths (i think).

Example:

//route (in your router file should have "name")
{ path: '/errors', name: 'EXAMPLE', component: ... }

//navigating
this.$router.push({
    name: 'EXAMPLE', 
    params: { errors: '123' }
});

Now it will have correct value in this.$route.params.

like image 178
euvl Avatar answered Oct 11 '22 18:10

euvl


If you don't want to use named routes you can try this:

ES6

this.$root.$router.push({
    path: `/dashboard/${error}`, 
    query: { test }
})

ES5

this.$root.$router.push({
    path: '/dashboard/' + error, 
    query: { test: 'test' }
})
like image 10
Rob Avatar answered Oct 11 '22 20:10

Rob