vue-cli项目中,我在index.html中直接引入particls的库,相关文件是放在static目录下的
<div id="particles-js"></div>
//引入库和配置文件
<script type="text/javascript" src="static/js/particles.min.js"></script>
<script type="text/javascript" src="static/js/app.js"></script>
这样是没问题的。现在就是有个需求,当用户url输入错误时,要跳转到404页面,守卫导航我是写在组件内的。
beforeRouteEnter:function(to, from, next){
// fetchData;
next(vm => {
vm.fetchData(function(result){
console.log(result);
if(result)
next();
else
next({name:'Home'}); // 跳转到home页面
});
})
},
页面能跳转,但是粒子不显示了,报如下错误
Uncaught SyntaxError: Unexpected token <
打开相关文件,发现里面内容被替换成index.html的内容(抱歉暂时贴不了图)
为什么?
大概知道是为啥了,history模式吗?两个外联文件用绝对路径
src="/static"
试试