新页面打开路由携带sessionStorage 基于(react umi 脚手架 ant-design-pro v5)


直接上代码

export const jumpRoutesInNewPage = (pathname) => {
    //http://localhost:8000/#/resultsmgmt
    let url = window.location.href;
    url = url.substring(0, url.lastIndexOf('/'));
    let link = document.createElement("a");
    //http://localhost:8000/#/pathname
    link.href = url + pathname;
    //新页面打开
    link.target = '_blank'; 
    // Chrome Edga rel="opener"  不丢失sessionStorage
    // 其他浏览器未测试
    link.rel = 'opener';
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
}