马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
作用:
刚打开一个页面时,是默认进入“/”的页面,重定向可以进入指定页面。
实现一:刚打开页面进入login页面;
- routes: [
- {
- path: '/',
- redirect: "/login",
- },
- {
- path: 'login',
- name: 'Login',
- component: () => import('../views/Login.vue'),
- meta: {isMain: true, title: mainTitle}
- },
- {
- path: "error",
- name: "Error",
- component: () => import('../views/Error.vue'),
- meta: {isMain: true, title: mainTitle}
- },
- ]
复制代码 进一步:刚打开页面显示的是Main.vue,在里面配置RouterView展示子路由,因为路由重定向redirect所以会展示login子路由,所以刚打开页面由"头部+login内容"组成;
- routes: [
- {
- path: '/',
- name: 'Main',
- component: Main,
- redirect: "/login",
- children: [
- {
- path: 'login',
- name: 'Login',
- component: () => import('../views/Login.vue'),
- meta: {isMain: true, title: mainTitle}
- },
- {
- path: "error",
- name: "Error",
- component: () => import('../views/Error.vue'),
- meta: {isMain: true, title: mainTitle}
- },
- ]
- }
- ]
复制代码 Main.vue
- <template>
- <div class="main">
- <div class="header">这是头部</div>
- <div class="content">
- <RouterView></RouterView>
- </div>
- </div>
- </template>
复制代码 实现二:不利用重定向默认展示login页面
- routes: [
- {
- path: '/',
- name: 'Login',
- component: () => import('../views/Login.vue'),
- meta: {isMain: true, title: mainTitle}
- },
- {
- path: "error",
- name: "Error",
- component: () => import('../views/Error.vue'),
- meta: {isMain: true, title: mainTitle}
- },
- ]
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |