/**
* Loading chunk * failed,vue-router懒加载出错问题。
* 解决办法:
* 1、直接使用组件
* 2、发生错误时,使用过router.onError
* eg:
* router.onError((error) => {
* const jsPattern = /Loading chunk (\S)+ failed/g
* const cssPattern = /Loading CSS chunk (\S)+ failed/g
* console.log(error, '路由出问题了~');
* const isChunkLoadFailed = error.message.match(jsPattern || cssPattern)
* console.log(isChunkLoadFailed, 'isChunkLoadFailed路由');
* const targetPath = router.history.pending.fullPath
* if (isChunkLoadFailed) {
* localStorage.setItem('targetPath', targetPath)
* window.location.reload()
* }
* })
*
* 3、在vue.config.js中配置publicPath(没有解决问题)
* eg:
* module.exports = defineConfig({
* publicPath: '/',
* )}
*/
Loading chunk * failed错误
最新推荐文章于 2024-06-27 12:05:04 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)