💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
https://segmentfault.com/a/1190000016919340 **问题1解决方法:捕获路由报错. (思路来源:[https://segmentfault.com/a/11...](https://segmentfault.com/a/1190000016382323))** ~~~ routers.onError((err) => { const pattern = /Loading chunk (\d)+ failed/g; const isChunkLoadFailed = err.message.match(pattern); if (isChunkLoadFailed) { let chunkBool = sessionStorage.getItem('chunkError'); let nowTimes = Date.now(); if (chunkBool === null || chunkBool && nowTimes - parseInt(chunkBool) > 60000) {//路由跳转报错,href手动跳转 sessionStorage.setItem('chunkError', 'reload'); const targetPath = routers.history.pending.fullPath; window.location.href = window.location.origin + targetPath; }else if(chunkBool === 'reload'){ //手动跳转后依然报错,强制刷新 sessionStorage.setItem('chunkError', Date.now()); window.location.reload(true); } } }) ~~~ **问题2解决方法: 经过问题排查发现,vue-cli默认build后的文件名格式为`js/[name].[chunkhash].js`,每次`npm run build`后有改动的文件hash值都会改变,上传后Nginx无法找到最新上传的文件,所以返回了默认`index.html`里的内容,我们的文件后缀名是`.js`自然无法识别`<html>`这种标签符号,导致console抛出`Uncaught SyntaxError:Unexpected token <`,我尝试修改`build/webpack.prod.conf.js`output输出文件名格式,目前问题已得到解决** ![](https://box.kancloud.cn/12750a54c3ef77786830ade9aea47928_680x132.png)