Vue路由配置是否含底部导航栏

余生长醉 提交于 2020-03-12 16:57:19
let barRoute = {
  path: '/',
  component: () => import('../view/basicView'),
  redirect: '/home',
  children: [ // 带底部导航
  ]
}
let routes = [
  barRoute,
  {
    name: 'home',
    component: () => import('../view/home'),
    meta: {
      title: '首页',
      hasBar: true
    }
  },
  {
    name: 'login',
    component: () => import('../view/login'),
    meta: {
      title: '登录'
    }
  }
];

// add route path
routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
  if(route.meta && route.meta.hasBar){
    barRoute.children.push(route)
  }
});
routes = routes.filter(route => {
  return !route.meta || !route.meta.hasBar
})
console.log(routes)
const router = new Router({ routes });

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  next();
});
basicView.vue写入底部导航代码

 

有底部导航,则配置meta.hasBar=true即可

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!