location.href和location.reload同时使用的问题?

let type=item.type,
url = location.protocol + '//' + location.host + '/web/'+type+'/show.html#/' + this.activity.activity_id+'/'+undefined+'/'+this.yiye.activity_id;
location.href = url;

上面type变化时正常跳转页面,只有hash改变时,不会刷新页面,于是我加上下面这句

location.reload();

现在hash值变了,上面会刷新页面,但当type改变时 页面却不会跳转了只是刷新了一遍,请问这是什么原因???

let pathname =location.pathname
location.href = url;
if(url.indexOf(pathname)!==-1){
   location.reload();
}

最后我是这样解决的,判断路径是否变化来调用reload()

阅读 2.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题