赞
踩
今天接到一个任务,hash模式的#不好看,让把使用scui框架的项目的路由模式变一下,将hash模式变为历史模式,记录一下这个过程及出现的问题。
原:
- import {createRouter, createWebHashHistory} from 'vue-router';
- const router = createRouter({
- history: createWebHashHistory(process.env.BASE_URL),
- routes: routes
- })
改为历史模式
- import {createRouter, createWebHistory} from 'vue-router';
- const router = createRouter({
- history: createWebHistory(process.env.BASE_URL),
- routes: routes
- })
但是刷新显示 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>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。