vue让router-view默认显示页面操作方法
场景:一个home页面,点击左边的菜单栏,右边显示页面,因此都知道在右边放一个router-view然后配置路由即可。
然而问题出现在:重新打开的时候,默认是白色空的。
那么解决办法是:
在router管理的index.js中
加上 redirect:'/xxxx'
{ path: '/home', name: 'home', component: home, meta: { requireauth: true // 添加该字段,表示进入这个路由是需要登录的 }, redirect:'/wxuser', children: [{ path: '/admin', name: '后台用户管理', component: admin, meta: { requireauth: true } }, { path: '/wxuser', name: '微信用户管理', component: wxuser, meta: { requireauth: true } }] }
扩展:
vue-router默认的开始界面
①利用利用redirect单独写一个路由
{ path: "/", redirect: "/home", }, { path: "/home", name: "home", component: () => import("../pages/home/index.vue"), //这里是路由懒加载,使访问更加高效 }, { path:"/login", name:"login", component: () => import("../pages/login/index.vue"), }
②router的children的初始页面,可以用redirect定义初始页面,也可以按①的方式
{ path: "/helloworld", name: "helloworld", component: helloworld, //进入时默认路由为"/1" redirect: "/1", children: [ { path: "/1", name: "ahomepage", component: ahomepage, }, { path: "/2", name: "one", component: one, }, { path: "/3", name: "two", component: two, }, { path: "/5", name: "nodeapi", component: nodeapi, }, { path: "/4", name: "arcgis", component: arcgis, }, { path: "/6", name: "try", component: try, }, { path: "/7", name: "echarts", component: echarts, }, { path: "/8", name: "geogis", component: geogis, }, { path: "/9", name: "less", component: less, }, ], },
到此这篇关于vue关于如何让router-view默认显示页面问题的文章就介绍到这了,更多相关vue router-view默认显示页面内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论