监听F5刷新,添加路由前缀

时间:2023-03-08 17:51:32

为了解决ninx反向代理,添加路由,但最终react的route还是不认识,研究了半天做个记录:

document.addEventListener("keydown",function(event){
if (event.code === 'F5') {
event.preventDefault();
console.info(event.code, event);
var pathname = location.pathname;
var newUrl = null;
if (pathname.indexOf('/sfgl') < 0) {
newUrl = location.origin + '/sfgl' + pathname;
console.log(newUrl);
window.location.assign(newUrl);
}
}
})