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: [
${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')}
]},
{path: '/', name: "init"},

View File

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