refactor(router): 优化路由生成逻辑和导航组件

- 修改路由生成逻辑,使用 name 作为 path,解决 path 未定义问题- 更新 sliderNav 组件中的路由跳转逻辑,使用 path 方式跳转
- 优化 url 参数处理,支持查询字符串
-调整路由配置模板,统一格式
This commit is contained in:
aixianling
2024-12-23 10:20:19 +08:00
parent 4ead05b251
commit 4684952973
2 changed files with 8 additions and 9 deletions

View File

@@ -53,9 +53,9 @@ const createRoutes = (config = {}) => {
{path: '/v', name: 'Home', component: () => import('../views/home'), children: [ {path: '/v', name: 'Home', component: () => import('../views/home'), children: [
${routes.map(e => { ${routes.map(e => {
// 解构每个路由的属性,用于生成路由配置 // 解构每个路由的属性,用于生成路由配置
const {name, label, path, esm} = e const {name, label, esm} = e
// 生成单个路由配置的字符串表示 // 生成单个路由配置的字符串表示
return `{name:"${name}",label:"${label}",path:"${path}",component:()=>import("../${esm}")}` return `{name:"${name}",label:"${label}",path:"${name}",component:()=>import("../${esm}")}`
}).join(',\n')} }).join(',\n')}
]}, ]},
{path: '/', name: "init"}, {path: '/', name: "init"},

View File

@@ -80,12 +80,11 @@ export default {
if (item.route == this.$route.name) { if (item.route == this.$route.name) {
//避免同一路由跳转的BUG vue-router官方BUG //避免同一路由跳转的BUG vue-router官方BUG
} else { } else {
let {route: name, path} = item let {component, path} = item, urlParams = ''
if (!name) { if (path.indexOf('?') > -1) {
this.$message.warning("暂无应用") urlParams = path.split('?').at(-1)
} else {
this.goto({name, query: qs.parse(path.split("?")?.[1])})
} }
this.goto({path: `/v/${[component, urlParams].filter(Boolean).join("?")}`})
} }
}, },
goto(item) { goto(item) {
@@ -219,7 +218,7 @@ export default {
} }
} }
:deep(.ai-menu ){ :deep(.ai-menu ) {
padding-left: 0; padding-left: 0;
flex: 1; flex: 1;
min-height: 0; min-height: 0;
@@ -233,7 +232,7 @@ export default {
} }
} }
:deep(.searchApp ){ :deep(.searchApp ) {
display: flex; display: flex;
align-items: center; align-items: center;
height: 44px; height: 44px;