//url符号#处理,替换#号为asqm
function replaceUrlJINtoAAB() {
//console.log(123366,'测试全局方法');
//添加时间:2022-7-21 15:05:43。url符号#处理,替换#号为asqm
console.log(8897,location.href);
if(location.href.indexOf('#')>=0){
history.replaceState(null,null, location.href.replace(/#{1,}/g,'asqm'));
}
var lastUrl=sessionStorage.getItem('last_url');
console.log(94456,'lastUrl='+lastUrl);
if(lastUrl!=null){
var currentURL= location.href;
currentURL=currentURL.substring(currentURL.indexOf('asqm'),currentURL.length);
//如果上一次的url与本次url相同,则不处理
if(currentURL===lastUrl){
return;
}
history.replaceState(null,null, location.href.replace(lastUrl,'asqm'));
}
console.log(778899,'第二个='+location.href);
history.replaceState(null,null, location.href.replace(/(asqm){1,}/g,'asqm'));
var url01=location.href;
//不区分大小写,全局匹配
var regK = new RegExp("(?<=[http|https]://[a-zA-Z0-9-.]+:{0,1}[0-9]*/).*",'ig')
url01=regK.exec(url01);
sessionStorage.setItem("last_url", url01);
//history.pushState(null, null, document.URL.replace('#','asqm'));
}
原url:
http://localhost:9000/#/see/index
替换后为
http://localhost:9000/asqm/see/index
vue页面调用:
export default {
name: 'SEE',
data() {
/*消息框注册到页面,添加时间:2022-7-18 15:43:04 */
window.myAlertError=this.$message.error;
},
created() {
//处理url的#号
this.$filters9.replaceUrlJINtoAAB();
},
methods: {
},
};