三,首页重定向+左侧菜单栏变为路由链接

一首页重定向
1,先新建一个Welcome.vue组件

<template>
    <div>
        <h3>Welcome</h3>
    </div>
</template>

2.在router文件夹index.jswen文件中引入Welcome.vue组件,并给home组件添加子路由。重定向到子路由上。
Welcome.vue

<template>
    <div>
        <h3>Welcome</h3>
    </div>
</template>

index.js

// 导入 Welcome组件
import Welcome from '../components/Welcome'

const routes = [
  // 当路径是/时,重定向路径/login
  { path: '/', redirect: '/login' },
  // 当路径是/login时,展示组件Login
  { path: '/login', component: Login },
  // 给home组件添加子路由,重定向
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [{ path: '/welcome', component: Welcome}]
  }
]

3.到home组件主体部分中添加路由占位符,展示Welcome组件

  <el-main>
      <!-- Welcome组件路由占位符 -->
      <router-view></router-view>
    </el-main>

二,左侧菜单栏变为路由链接
1.给菜单添加:router="true",代表是否使用 vue-router 的模式,启用该模式会在激活导航时以 index 作为 path 进行路由跳转

 <!-- 侧边栏菜单 -->
      <el-menu
      background-color="#333744"
      text-color="#fff"
      active-text-color="#ffd04b"
      :unique-opened="true"
      :collapse="isCollapse"
      :collapse-transition="false"
      :router="true">

2.二级菜单通过index属性指定跳转地址的显示,在跳转地址前还要加‘/’

 <!-- 通过v-for循环menuList中二级菜单数据展示菜单数据 -->
      <el-menu-item :index="'/'+subItem.path " v-for="subItem in item.children" :key="subItem.id">
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容