简体   繁体   中英

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. 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 :

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 },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM