首页 > 其他分享 >Vue router 二级默认路由设置

Vue router 二级默认路由设置

时间:2023-06-05 23:35:57浏览次数:35  
标签:Vue false name component meta import router path 路由

一、起因

打开默认地址 / (http://localhost:5432/),home 页面有空白,因为没有指定默认打开的子页。

// router.js
export const constantRoutes = [
    {
        path: '/',
        component: () => import('@/views/MainView'),
        name: 'Index',
        meta: { keepAlive: false },
        children: [
            {
                path: '/enc',
                component: () => import("@/components/Enc"),
                name: 'enc',
                meta: { keepAlive: false },
            },
            {
                path: '/about',
                component: () => import("@/components/About"),
                name: 'about',
                meta: { keepAlive: false },
            }
        ]
    }
]
const router = createRouter({
    history: createWebHashHistory(import.meta.env.VITE_APP_BASE_PATH),
    routes: constantRoutes,
});

二、设置

要设置 redirect 属性。

export const constantRoutes = [
    {
        path: '/',
        component: () => import('@/views/MainView'),
        name: 'Index',
        redirect: '/enc',
        meta: { keepAlive: false },
        children: [
            {
                path: '/enc',
                component: () => import("@/components/Enc"),
                name: 'enc',
                meta: { keepAlive: false },
            },
            {
                path: '/about',
                component: () => import("@/components/About"),
                name: 'about',
                meta: { keepAlive: false },
            }
        ]
    }
]
const router = createRouter({
    history: createWebHashHistory(import.meta.env.VITE_APP_BASE_PATH),
    routes: constantRoutes,
});

标签:Vue,false,name,component,meta,import,router,path,路由
From: https://www.cnblogs.com/echohye/p/17459287.html

相关文章

  • 【VUE】Vue 快速入门 笔记基础01
    一、vue相关了解1、概述Vue.js是一种流行的JavaScript框架,用于构建响应式、交互式的前端Web界面。它采用了基于组件的开发模式,允许在单个页面中使用多个可重用的组件,提高了代码的复用性和维护性。只关心视图层,自底向上.遵守SOC关注点分离原则(术有专攻,只关注一点)HTML+CSS......
  • WPF自学入门(四)WPF路由事件之自定义路由事件
      在上一篇博文中写到了内置路由事件,其实除了内置的路由事件,我们也可以进行自定义路由事件。接下来我们一起来看一下WPF中的自定义路由事件怎么进行创建吧。创建自定义路由事件分为3个步骤:1、声明并注册路由事件。2、利用CLR事件包装路由事件(封装路由事件)。3、创建可以激发路由......
  • vue之三种与后端交互的方式
    目录一、vue与后端交互之Ajax情况一:出现了跨域问题前端:index.html后端:main.py情况二:解决了跨域问题前端:index.html二、vue与后端交互之fetch简介fetch介绍后端:main.py前端:index.html三、vue与后端交互之axios1.简介html前端一、vue与后端交互之Ajax情况一:出现了跨域问题前端:in......
  • asp.net core 中的路由
          ......
  • Vuex的五个属性及使用方法示例
    一、Vuex简介Vuex是Vue.js的状态管理库,它通过中心化的状态管理使得组件间的数据共享更加容易。Vuex包含五个核心属性:state、getters、mutations、actions和modules。Vuex是Vue.js的状态管理库,它提供了一种集中式存储管理应用程序中所有组件的状态,并将其分离到一个可预测的状态容器......
  • vue3+vant4+vuex4入门案例
    案例用的是vant-ui库,你可换成你自己用的ui库即可。安装vuex依赖包npminstallvuex--savemain.js引用vuex,并挂载到vue中importstorefrom'./store';app.use(router).use(store); add.vue页面:1<template>2<h2>加法{{$store.getters.showNum}}</h2......
  • Vue购物车展示功能
    1.基本购物车<body><divid="app"><divclass="container-fluid"><divclass="row"><divclass="col-md-6col-md-offset-3"><h1class="text-cent......
  • Cisco 路由器登录标语
    Router(config)#bannerlogin'haha'设置本地登录标语Router(config)#bannermotd'xixi'设置启动标语......
  • Vue基础之表单控制 ,v-model进阶,箭头函数,JS循环
    目录一、表单控制1.checkbox选中2.radio单选3、checkbox多选4.购物车案例-结算二、v-model进阶三、箭头函数es6的语法1无参数,无返回值2有一个参数,没有返回值,可以省略括号3多个参数,不能省略括号4多个参数,不能省略括号,一个返回值5一个参数,一个返回值四、补充:JS循环一、表......
  • vue3+vant4+vuex4实现todolist备忘录案例
    案例图片如下:  1<van-cell-group>2<van-cell>3<van-row>4<van-colspan="20">5<van-field6:value="content"7@change="handl......