vue history模式 二级路由报错 Uncaught SyntaxError: Unexpected token ‘<‘

编程入门 行业动态 更新时间:2024-10-25 17:18:07

vue history模式 二级路由<a href=https://www.elefans.com/category/jswz/34/1771188.html style=报错 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 ‘<‘

本文发布于:2023-12-08 03:28:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1672222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报错   路由   模式   history   vue

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!