document.referrer是用来获取跳转链接的来源,正规的解释是:referrer 属性可返回载入当前文档的文档的 URL
例子:
当我们点击有referrer的a标签的时候,在百度页面我们可以看到referrer。
当我们点击ifame中嵌套的a标签的时候,在百度页面我们可以看到referrer为空字符串。
此外,想要区分本身自己的链接,还是蜘蛛爬虫出来的链接来区分跳转路径
let regexp = /\.(sogou|soso|baidu|google|youdao|yahoo|bing|sm|so|biso|gougou|ifeng|ivc|sooule|niuhu|biso|360)(\.[a-z0-9\-]+){1,2}\//ig;
let where = document.referrer;
where = where.toLowerCase(); //转为小写
//console.log("=======",where);
if (!regexp.test(where) && this.codeText=="/") {
this.$router.push("/");
}