您可能错误的是在用户登录之前尝试缓存需要用户权限的页面.所以会发生的情况是:浏览器尝试检索路由,但服务器会提供登录页面,因为用户未登录.
你可能需要做什么:
credentials: include.它将是这样的:```/*sw.js*/
var cacheName = 'yourCacheName-vx.x.x';
// The route for which you need to be logged in. It's a Request Object.
var appRequest = new Request('/da-private-route', { credentials: 'include' });
var urlsToCache = [
appRequest, // you add it to your things to cache
'/manifest.json',
'/css/styles.css',
'/js/scripts.js',
// other resources…
];
// Installation.
self.addEventListener('install', e => {
e.waitUntil(
self.skipWaiting().then(function() {
caches.open(cacheName).then(function(cache) {
return cache.addAll(urlsToCache);
})
})
);
});
/* [continue your sw…] */
Run Code Online (Sandbox Code Playgroud)
```
| 归档时间: |
|
| 查看次数: |
1521 次 |
| 最近记录: |