当前位置:   article > 正文

scui中将路由模式由hash模式变为历史模式

scui

今天接到一个任务,hash模式的#不好看,让把使用scui框架的项目的路由模式变一下,将hash模式变为历史模式,记录一下这个过程及出现的问题。

原:

  1. import {createRouter, createWebHashHistory} from 'vue-router';
  2. const router = createRouter({
  3. history: createWebHashHistory(process.env.BASE_URL),
  4. routes: routes
  5. })

改为历史模式

  1. import {createRouter, createWebHistory} from 'vue-router';
  2. const router = createRouter({
  3. history: createWebHistory(process.env.BASE_URL),
  4. routes: routes
  5. })

但是刷新显示 Cannot GET /PrintLabel/ShipAccount

原因是因为在vue.config.js中设置了publicPath:'',将其去掉就解决了

在控制台中还有下面的问题

GET http://localhost:2900/PrintLabel/config.js?1673315647961 net::ERR_ABORTED 404 (Not Found)

Refused to execute script from 'http://localhost:2900/PrintLabel/config.js?1673315647961' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

原因是在html.index下config.js路径引入错误

<script type="text/javascript">       document.write("<script src='config.js?"+new Date().getTime()+"'><\/script>");</script>

config.js是与html.index同一目录下的,前面加个/就可以了

<script type="text/javascript">       document.write("<script src='/config.js?"+new Date().getTime()+"'><\/script>");</script>

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号