[英]router push doesn't work in vuejs when i want to pass params
When I want to use programmatic navigation by vue-router
package it works, but when I want to pass params to a component with router.push
methods, it doesn't work at all.当我想通过
vue-router
包使用程序化导航时,它可以工作,但是当我想使用router.push
方法将参数传递给组件时,它根本不起作用。 Does anybody have a solution?有人有解决方案吗?
My code here:我的代码在这里:
import VueRouter from 'vue-router'
import routes from './routes';
const router = new VueRouter({routes});
Vue.use(VueRouter);
and the push code:和推送代码:
router.push({ name: 'reportArchive', params: {token: token} });
My route config:我的路线配置:
{ path: '/reportArchive', name: 'reportArchive', component: reportArchive },
If you really want to pass param, you will need to set the route to accept param, just like below :如果你真的想传递参数,你需要设置路由来接受参数,就像下面一样:
{ path: '/reportArchive/:token', name: 'reportArchive', component: reportArchive },
This is as per Eldar's answer above, but if you want to pass url query parameters, you need to use query instead of params in the code, for example :这是根据上面 Eldar 的回答,但是如果要传递 url 查询参数,则需要在代码中使用 query 而不是 params,例如:
router.push({ name: 'reportArchive', query: {token: token} });
Your route definition doesn't accept a paramater.您的路线定义不接受参数。 You should define your route as below :
你应该定义你的路线如下:
{ path: '/reportArchive/:token', name: 'reportArchive', component: reportArchive },
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.