2016-11-18 26 views
5

空我用這個

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

在我的組件重定向到其他URL當一些錯誤發生。問題是,當我想要訪問儀表板組件中的params字段時,它是空的。該query領域運作良好。我試圖通過this.$route.params.errors訪問它。

回答

7

您只能使用params路徑(我認爲)與named路徑。

例子:

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

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

現在它將會在this.$route.params有正確的值。

+0

好消息: )謝謝,效果很好。 –

+0

你知道這個限制的原因是什麼? – andresgottlieb

+0

悲劇限制。 – mystrdat

1

如果希望使用命名路由你可以試試這個:

ES6

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

ES5

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