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 ''
  }
}
相关推荐
lUie INGA15 分钟前
Go-Gin Web 框架完整教程
前端·golang·gin
ZC跨境爬虫28 分钟前
跟着 MDN 学 HTML day_8:(高级文本语义标签+适配核心功底)
前端·css·笔记·ui·html
承渊政道31 分钟前
【动态规划算法】(回文串问题解题框架与经典案例)
数据结构·c++·学习·算法·leetcode·动态规划·哈希算法
Achou.Wang36 分钟前
使用互斥锁进行同步
golang
jieyucx41 分钟前
Go 零基础数据结构:链表的增删改查(像串珠子一样简单)
数据结构·链表·golang
yuweiade41 分钟前
GO 快速升级Go版本
开发语言·redis·golang
橙子1991101612 小时前
UI 绘制相关
ui
Math_teacher_fan13 小时前
Flutter 跨平台开发实战:鸿蒙与音乐律动艺术(六)、Lissajous 利萨茹曲线:频率耦合的轨迹艺术
flutter·ui·数学建模·华为·harmonyos·鸿蒙系统
geovindu16 小时前
go: Strategy Pattern
开发语言·设计模式·golang·策略模式
开发小程序的之朴16 小时前
基于Go语言的企业级CMS系统架构设计与性能分析——以AnQiCMS为例
开发语言·golang·系统架构