Commit 465f2219 authored by 蔡伟's avatar 蔡伟

Merge branch 'feat/layout-style' into 'dev'

feat(*): 路由跳转问题修改

See merge request !2
parents 9243b184 7a56a91f
...@@ -57,11 +57,11 @@ export default { ...@@ -57,11 +57,11 @@ export default {
if (route.matched && route.matched.length > 0) { if (route.matched && route.matched.length > 0) {
const matchedRoutes = route.matched; const matchedRoutes = route.matched;
// 添加首页项(可选) // // 添加首页项(可选)
breadcrumbList.value.push({ // breadcrumbList.value.push({
path: '/dashboard', // path: '/dashboard',
meta: { title: '首页' } // meta: { title: '首页' }
}); // });
// 添加匹配的路由 // 添加匹配的路由
matchedRoutes.forEach(item => { matchedRoutes.forEach(item => {
......
...@@ -16,13 +16,15 @@ ...@@ -16,13 +16,15 @@
<el-icon><location /></el-icon> <el-icon><location /></el-icon>
<span>{{getMenuTitle(item)}}</span> <span>{{getMenuTitle(item)}}</span>
</template> </template>
<el-menu-item v-for="(item_son, index_son) in item.children" :key="item_son.path" :index="index + '_' + index_son"> <el-menu-item v-for="(item_son, index_son) in item.children" :key="item_son.path" :index="index + '_' + index_son"
<router-link :to="item.path + '/' + item_son.path">{{getMenuTitle(item_son)}}</router-link> @click="handleClick(item_son.path)">
<span>{{getMenuTitle(item_son)}}</span>
<!-- <router-link :to="item.path + '/' + item_son.path">{{getMenuTitle(item_son)}}</router-link> -->
</el-menu-item> </el-menu-item>
</el-sub-menu> </el-sub-menu>
<el-menu-item v-else :index="index + ''" class="submenu-box"> <el-menu-item v-else :index="index + ''" class="submenu-box" @click="handleClick(item.path)">
<el-icon><setting /></el-icon> <el-icon><setting /></el-icon>
<span><router-link :to="item.path">{{getMenuTitle(item)}}</router-link></span> <span>{{getMenuTitle(item)}}</span>
</el-menu-item> </el-menu-item>
</template> </template>
</el-menu> </el-menu>
...@@ -38,6 +40,19 @@ import { ...@@ -38,6 +40,19 @@ import {
Setting, Setting,
} from "@element-plus/icons-vue"; } from "@element-plus/icons-vue";
import {routes} from "../router/index.js"; import {routes} from "../router/index.js";
import { useRouter } from 'vue-router'
const router = useRouter()
const handleClick = (path) => {
console.log(path);
if (path.startsWith('/')) {
router.push(path) // 绝对路径,直接跳转
} else {
router.push('/' + path) // 相对路径,补全
}
}
const routerList = routes[0].children; const routerList = routes[0].children;
const handleOpen = (key, keyPath) => { const handleOpen = (key, keyPath) => {
console.log(key, keyPath); console.log(key, keyPath);
......
import { createWebHistory, createRouter } from 'vue-router' import { createWebHistory, createRouter } from 'vue-router'
import Dashboard from '../views/dashboard/index.vue'
import HomeView from '../views/HomeView.vue' import HomeView from '../views/HomeView.vue'
import AboutView from '../views/AboutView.vue' import AboutView from '../views/AboutView.vue'
import User from '../views/user.vue' import User from '../views/user.vue'
...@@ -11,65 +12,49 @@ const routes = [ ...@@ -11,65 +12,49 @@ const routes = [
path: '/', path: '/',
component: Layout, component: Layout,
children: [ children: [
{ {
path: '/dashboard', path: '/dashboard',
component: AboutView, component: Dashboard,
meta: { meta: { title: '首页' },
title: '首页', },
}, {
}, path: '/overview',
{ component: HomeView,
path: '/2', meta: { title: '除尘器总览' },
},
{
path: '/device-management',
component: AboutView,
meta: { title: '设备管理' },
},
{
path: '/monitor',
component: AboutView,
meta: { title: '除尘器监控' },
},
{
path: '/alerts',
component: AboutView,
meta: { title: '告警总览' },
},
{
path: '/my-loop',
meta: { title: '我的闭环' },
children: [
{
path: '/my-loop/profile',
component: HomeView, component: HomeView,
meta: { meta: { title: '我的待办' },
title: '除尘器总览', },
}, {
}, path: '/my-loop/posts',
{
path: '/3',
component: AboutView,
meta: {
title: '设备管理',
},
},
{
path: '/4',
component: AboutView, component: AboutView,
meta: { meta: { title: '我的已办' },
title: '除尘器监控', },
}, ]
}, },
{
path: '/5',
component: AboutView,
meta: {
title: '告警总览',
},
},
{
path: '/6',
meta: {
title: '我的闭环',
},
children: [
{
path: 'profile',
component: HomeView,
meta: {
title: '我的待办',
},
},
{
path: 'posts',
component: AboutView,
meta: {
title: '我的已办',
},
},
],
},
] ]
}, },
{ {
path: '/login', path: '/login',
component: Login, component: Login,
......
<template>
<div class="page-container">
dashborad
</div>
</template>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment