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 ''
  }
}
相关推荐
花酒锄作田4 天前
Gin 框架中的规范响应格式设计与实现
golang·gin
修炼前端秘籍的小帅4 天前
Stitch——Google热门的免费AI UI设计工具
前端·人工智能·ui
王码码20354 天前
Flutter for OpenHarmony:socket_io_client 实时通信的事实标准(Node.js 后端的最佳拍档) 深度解析与鸿蒙适配指南
android·flutter·ui·华为·node.js·harmonyos
2501_921930835 天前
Flutter for OpenHarmony:第三方库实战 chewie 视频播放器UI组件详解
flutter·ui
Full Stack Developme5 天前
哈希是什么
算法·哈希算法
qwfys2005 天前
How to install golang 1.26.0 to Ubuntu 24.04
ubuntu·golang·install
梵得儿SHI5 天前
Vue3 生态工具实战宝典:UI 组件库 + 表单验证全解析(Element Plus/Ant Design Vue/VeeValidate)
前端·vue.js·ui·elementplus·vue性能优化·antdesignvue·表单验证方案
Unity游戏资源学习屋5 天前
【Unity UI资源包】GUI Pro - Casual Game 专为休闲手游打造的专业级UI资源包
ui·unity
Frostnova丶5 天前
(1)LeetCode 1. 两数之和
leetcode·哈希算法
秦jh_5 天前
【C++】哈希扩展
开发语言·c++·哈希算法