先贴一下我的路由配置:
export default new Router({
routes: [
{
path: '/',
redirect: '/home'
},
{
path: '/home',
name: 'Home',
component: Home,
children: [
{path: '/',name: 'HomeComponent', component: HomeComponent},
{path: '/homeComponent',name: 'HomeComponent', component: HomeComponent},
{path: '/myComponent',name: 'MyComponent', component: MyComponent},
]
},
{path:'/imitate',name:Imitate,component:Imitate}//答题列表
]
})
现在有个需求是点击二级路由的一个按钮,跳到一级路由 imitate。
尝试了几种方式都失败了。
<router-link :to="{name:'Imitate'}">测试路由</router-link>//失败
<router-link :to="imitate">测试路由</router-link>//失败
//省略其他失败的方式······
后来使用vue-router的path解决了。
<router-link :to="{path:'/imitate'}">测试路由</router-link>
网友评论