出问题的代码,
path: '/user/:username/',
name: 'User',
component: User,
redirect: '/user/:username/posts'
输入user/100
后,跳转到了user/:username/posts
,100没有传递给重新向的路由。
解决方法:
path: '/user/:username/',
name: 'User',
component: User,
redirect: to => {
const {hash, params, query} = to
if (params.username) {
return '/user/'+params.username+'/posts'
}
},
具体内容,见vue文档和示例: