yudao-ui-go-view路由同时支持history及hash

yudao-ui-go-view源码只支持hash路由,切换history模式,预览数据报表会报错。

效果如下,地址栏url不一样了:

1、配置路由模式

src\router\index.ts 中导入函数createWebHistory,并配置到router上:

javascript 复制代码
import { createRouter, createWebHashHistory,createWebHistory, RouteRecordRaw } from 'vue-router'


const router = createRouter({
  history: createWebHistory(''),
  // history: createWebHashHistory(''),  // hash 模式
  routes: constantRouter,
  strict: true,
})

2、修改生成预览地址函数

src\utils\router.ts修改 previewPath函数如下:

javascript 复制代码
 export const previewPath = (id?: string | number) => {
  const { origin, pathname } = document.location
  const path = fetchPathByName(PreviewEnum.CHART_PREVIEW_NAME, 'href')
  if(path.startsWith("#")){ // history=hash
    return `${origin}${pathname}${path}/${id || fetchRouteParamsLocation()}`
  } else {
    return `${origin}${path}/${id || fetchRouteParamsLocation()}`
  }
}

3、修改获取url参数

src\utils\router.ts修改 fetchRouteParamsLocation 函数如下:

javascript 复制代码
export const fetchRouteParamsLocation = () => {
  try {
    const route = useRoute()
    if(route.params.id && route.params.id.length){
      return route.params.id[0];
    } else {
      return route.params.id;
    }
    
    // return document.location.hash.split('/').pop() || ''
  } catch (error) {
    window['$message'].warning('查询路由信息失败,请联系管理员!')
    return ''
  }
}
相关推荐
microrain8 小时前
从硬编码到热插拔:SagooIoT插件架构如何打破物联网平台的扩展瓶颈
物联网·golang·开源·sagooiot
geovindu10 小时前
go:Backtracking Algorithm
开发语言·后端·算法·golang·回溯算法
qq_4523962310 小时前
第六篇:《并发编程核心:Goroutine 与 Channel》
golang
llwszx10 小时前
【Java/Go后端手撸原生Agent(第五篇):多工具并行调用 + BashTool执行引擎 + Judge证据链升级】
java·后端·golang·状态机·pydantic·agnet·llm-as-judge
FfHUCisI10 小时前
Go语言程序结构 —— 变量、声明与零值机制
golang
薛定谔的猫-菜鸟程序员11 小时前
一个 Skill 如何让大模型拥有专业 UI 能力?——ui-ux-pro-max 架构深度拆解与 Skill 设计方法论
人工智能·ui
超人不会飞_Jay11 小时前
Go课程2
开发语言·后端·golang
流星白龙20 小时前
【Redis】7.Hash表
数据库·redis·哈希算法
晴空了无痕1 天前
从 Go 基础到 K8s:一条可落地的 Go 服务端成长路线
开发语言·后端·golang·kubernetes
FrameNotWork1 天前
HarmonyOS 6.0 文件加密与安全存储:从哈希到硬件级密钥管理全链路实战
安全·哈希算法·harmonyos