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 ''
  }
}
相关推荐
范同学~10 小时前
多个表单如何用element ui 校验
javascript·vue.js·ui
JohnnyDeng9410 小时前
Paging 3 分页加载架构全解析:从数据源到 UI 的完整链路
android·ui·kotlin
李燚10 小时前
ReAct 循环的 50 行 Go 实现,逐行拆解
javascript·人工智能·react.js·golang·aigc·agent
ZC跨境爬虫10 小时前
跟着 MDN 学CSS day_8:(盒模型完全解)
前端·javascript·css·ui·交互
ZC跨境爬虫11 小时前
跟着 MDN 学CSS day_6:(伪类和伪元素详解)
前端·javascript·css·数据库·ui·html
x***r15111 小时前
AxureRP-Setup安装步骤详解(附Axure RP原型设计与汉化教程)
ui·axure·photoshop
ZC跨境爬虫12 小时前
模块化烹饪小程序开发日记 Day6:(菜谱列表接口开发与日志调试实践)
前端·javascript·css·ui·微信小程序·html
lzp079112 小时前
C#如何优雅处理引用类型的深拷贝(贰)
spring boot·后端·ui
JunLa12 小时前
Java语法糖
java·python·哈希算法