vue-router重定向
在router下的index.js配置路由时,有时候,配置不同的路由,但是,希望跳转到同一个页面,这个时候就需要使用redirect进行重定向,这样,就可以跳转到同一个页面。普通的重定向(不需要传递任何的参数):export default new Router({routes: [{path: '/',name: 'HelloWorld',...
·
在router下的index.js配置路由时,有时候,配置不同的路由,但是,希望跳转到同一个页面,这个时候就需要使用redirect进行重定向,这样,就可以跳转到同一个页面。
普通的重定向(不需要传递任何的参数):
export default new Router({
routes: [
{
path: '/',
name: 'HelloWorld',
component: HelloWorld,
children: [
{//在地址为空时,直接跳转cell路由
path:'',
redirect:'/cell'
},
{
path: '/cell',
component: Cell
}]
}
]
})
在重定向时,不需要配置component组件,只需要配置redirect,设置重定向的路由。
重定向时需要传递参数
export default new Router({
routes: [
{
path: '/',
name: 'HelloWorld',
component: HelloWorld,
children: [
{//在地址为空时,直接跳转cell路由
path:'',//默认缺省值
redirect:'/cell'
},
{
path: '/cell',
component: Cell
},{
path:'/city/:cityid',
component:City
},{
//本来配置的路由路径 /city/:cityid 是一个城市页面 传递的参数为 cityid 但是 我们可以设置重定向 /province/:cityid 同样到城市页面
path:'/province/:cityid',
redirect:'/city/:cityid'
}]
}
]
})
更多推荐
已为社区贡献4条内容
所有评论(0)