报错 Uncaught SyntaxError: Unexpected token ‘<‘"/>
vue history模式 二级路由报错 Uncaught SyntaxError: Unexpected token ‘<‘
vue项目,路由模式history。存在二级路由
第一次打开二级路由页面时正常。但再次刷新就会报错。
Uncaught SyntaxError: Unexpected token ‘<‘
上网查了很多资料,有nginx配置问题,也有代码配置问题。我参照网上说法改了nginx配置之后未解决。后来看到代码是有个文件未找到,路径错误了。改了路径之后好用了。我做了如下修改:
1.nginx配置
nginx的配置中要加上' try_files $uri $uri/ /index.html; '
location / { root /etc/nginx/html/5173auth/dist;index index.html index.html; try_files $uri $uri/ /index.html; }
2.vue.config.js
如果第1步操作未解决问题,就要看看publicPath。需要将值设置为'/'根目录。
如果有安装一些插件了,也要去看一看配置的目录是否正确。
我配置完publicPath:'/',是不好用的。因为我安装了插件AddAssetHtmlPlugin。这里也设置了一些vendor的publicPath。之前是忽略了这个地方。所以一直未好用。
plugins.push(new AddAssetHtmlPlugin({// dll文件位置filepath: path.resolve(__dirname, "./public/vendor/vendor.dll.js"),// dll 引用路径publicPath: "/vendor",// dll最终输出的目录outputPath: "/vendor",}));
将publicPath和插件里的publicPath都设置成'/'之后就好用了。
更多推荐
vue history模式 二级路由报错 Uncaught SyntaxError: Unexpected token ‘<‘
发布评论