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
}
}
以上代碼有三個作用
- 自動添加問號(?)
- 自動把分隔符由#!變成#
- 分隔符後面,自動判斷是否爲斜槓(/),沒有則添加上