Vue Router中调用this.$router.push() 时,location使用path无法传入params

Vue Router中调用this.$router.push() 时,location使用path无法传入params

解决方法:

给动态路由取名字,然后在location中使用name指向路由的名字,这样就可以通过params传参数

下面这段是来自Vue Router的官网的代码

const userId = '123'
router.push({ name: 'user', params: { userId } }) // -> /user/123
router.push({ path: `/user/${userId}` }) // -> /user/123
// This will NOT work
router.push({ path: '/user', params: { userId } }) // -> /user
原文地址:https://www.cnblogs.com/Blithe-Chiang/p/14415275.html