美文网首页
HTML5无刷新修改Url,history pushState/

HTML5无刷新修改Url,history pushState/

作者: 无名程序猿 | 来源:发表于2019-06-14 13:57 被阅读0次
  • 出现的问题:
    react项目中url使用 “#” 拼接,使用外部链接直接访问首页后,退出登录导致页面循环登录首页。
  • 解决方案:
    在退出登录操作中无刷新状态下修改页面url,之后经过用户路由判断自动跳转到登录页面。
  • 具体代码:
history.replaceState(null, '', '/login');
首页按钮操作方法.png global方法.png

history中的pushState和replaceState是一个HTML5的新接口,他们的作用非常大,可以做到改变网址却不需要刷新页面,这个特性后来用到了单页面应用中比如:vue-router,react-router-dom里面,
参考链接:
HTML5无刷新修改Url,history pushState/replaceState

相关文章

网友评论

      本文标题:HTML5无刷新修改Url,history pushState/

      本文链接:https://www.haomeiwen.com/subject/gwgufctx.html