Javascript 在React中导航到跨源URL时出现问题
有没有办法从React.js应用程序导航到跨源URLJavascript 在React中导航到跨源URL时出现问题,javascript,html,reactjs,service-worker,progressive-web-apps,Javascript,Html,Reactjs,Service Worker,Progressive Web Apps,有没有办法从React.js应用程序导航到跨源URL window.location.href=**跨源url** 这只在第一次尝试时起作用,然后不起作用,因为应用程序保存为PWA。由于缓存的原因,它只是重定向到同一个源。我通过在下面的serviceWorker.js中添加代码片段解决了这个问题 window.addEventListener("load", () => { // ... if (isAPIRoute()) { console.info("un
window.location.href=**跨源url**
这只在第一次尝试时起作用,然后不起作用,因为应用程序保存为PWA。由于缓存的原因,它只是重定向到同一个源。我通过在下面的
serviceWorker.js中添加代码片段解决了这个问题
window.addEventListener("load", () => {
// ...
if (isAPIRoute()) {
console.info("unregistering service worker for api route");
unregister();
console.info("reloading");
window.location.reload();
return false;
}
// ...
}
function isAPIRoute() {
return window.location.pathname.startsWith("/api");
}
请尝试window.location.replace(),这是serviceworker的问题。。。默认情况下,它缓存server@YosiLeibmanfor例如,我有“test.com”作为我的主url。。。“test.com/api/facebook”是api的url。。。但是服务人员缓存/api/facebook并且只返回主页。。。因此,我想阻止serviceworker中某些url匹配中的缓存