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

 

为了解决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);
            }
          }
        })

  

posted @ 2019-01-09 15:27  纸鸢&红豆·绿豆  阅读(633)  评论(0编辑  收藏  举报