vue3 ts路由配置,自动显示首页指定页面,element push根据地址栏显示对应的菜单

/ 表示默认现实的根据目录,redirect表示路由重定向 admin/dashboard,浏览器输入www.baidu.com的时候默认会跳转到重定向页面

复制代码
{
    path: "/",
    component: Layout,
    // 写法一
        // redirect: "/shop"
        // 写法二
    redirect: (to => { return { path: `admin/dashboard` } }),
    children:[{
      path: `admin/dashboard`,
      name: "home", 
      component: () => import("@/views/home/index.vue"),
      meta:{title:"首页11",icon: 'icon-huahua_taiyangnengguangfu'}
    },]
},

404页面

复制代码
{
  path: '/404',
  component: () => import('@/views/404/index.vue')
},
{
      path: '/:pathMatch(.*)', //路由不存在的时候,自动跳转到404
      redirect: '/404'
}

element push浏览器输入路由,导航菜单的默认选中

复制代码
import { useRouter,RouteRecordRaw,useRoute } from 'vue-router'
const useRoute1=useRoute()
const activeMenu=computed(()=>{
    // const route:any=routerData
    const { meta, path } = useRoute1
    if ("activeMenu" in meta) {
        return meta.activeMenu
      }
      return path
    
})

default-active使用上面的activeMenu就可以

复制代码
<el-menu
                        :default-active="activeMenu"
                       ...
                        >
相关推荐
一点七加一20 小时前
Harmony鸿蒙开发0基础入门到精通Day09--JavaScript篇
开发语言·javascript·ecmascript
_安晓20 小时前
Rust 中精确大小迭代器(ExactSizeIterator)的深度解析与实践
java·前端·python
烛阴20 小时前
从create到yield:Lua协程完全上手指南
前端·lua
薛一半20 小时前
Vue3的Pinia详解
前端·javascript·vue.js
浅影歌年21 小时前
vue3模块中引用公共css变量文件
前端
盼哥PyAI实验室1 天前
从搭建到打磨:我的纯前端个人博客开发复盘
前端·javascript
前端初见1 天前
2025前端面试题大合集
前端
用户904706683571 天前
vue3.5新特性——useTemplateRef
前端
嘉琪0011 天前
vue3+ts面试题(一)JSX,SFC
前端·javascript·react.js
何贤1 天前
🪐 行星科技概念官网!Hero Section 回归!(Three.js ✨)
前端·javascript·three.js