代码片段 URL

来源:互联网 发布:get软件买到假鞋 编辑:程序博客网 时间:2024/06/05 21:01
function directRightUrl () {  let paths = window.location.href.split('#')  paths[1] = paths[1] || '/'  // 老式的#!分隔跳转  if (paths[0].charAt(paths[0].length - 1) !== '?') {    paths[0] = `${paths[0]}?`  }  if (paths[1].charAt(0) === '!') {     paths[1] = paths[1].substr(1)  }  let url = `${paths[0]}#${paths[1]}`  if (window.location.href !== url) {    window.location.href = url  }}



以上代码有三个作用

  1. 自动添加问号(?)
  2. 自动把分隔符由#!变成#
  3. 分隔符后面,自动判断是否为斜杠(/),没有则添加上

0 0
原创粉丝点击