问题描述
当定义一个动态路由如/user/:id
时,在定义一个正常路由/user/edit
,但是当访问后者的时候,跳转到了前面的路由,不知道该怎么匹配
相关代码
const router = new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
component: () => import('./views/index/Index.vue'),
children: [
{
path: '/',
redirect: {
name: 'index'
}
},
{
path: '/index',
name: 'index',
component: () => import('./views/pages/Home.vue')
},
{
path: 'user/:id',
name: 'user_post',
component: ()=>import('./views/pages/Article.vue')
}
]
},
{
path: '/user',
component: () => import('./views/users/User.vue'),
children: [
{
path: '',
redirect: {
name: 'profile'
}
},
{
path: 'profile',
name: 'profile',
component: () => import('./components/user/Profile.vue')
},
{
path: 'editor',
name: 'editor',
component: () => import('./components/user/Editor.vue')
}
]
}
]
})
我期望的是首页中通过用户id访问用户的首页,然后/user/profile
、/user/editor
等是登录之后用户首页信息、编辑文章等的路由,但是现在访问/user/editor
直接跳转到/user/:id
即user_post的路由了,不知道有什么好的解决办法吗?
之前也遇到过,但是没想到办法,只能将
/user/:id
转换成query访问