From 2c96d5144cf6e5705ff9d2a1f48703bf5938d7f2 Mon Sep 17 00:00:00 2001 From: chenhang Date: Tue, 30 Jun 2026 15:08:18 +0800 Subject: [PATCH] fix(pwa): add offline fallback route --- src/app/sw.ts | 8 ++-- src/app/~offline/page.tsx | 84 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 src/app/~offline/page.tsx diff --git a/src/app/sw.ts b/src/app/sw.ts index ddb9afc5..e35c1510 100644 --- a/src/app/sw.ts +++ b/src/app/sw.ts @@ -17,9 +17,9 @@ * - clientsClaim: true 新 SW 立即接管所有打开的 client * - navigationPreload: 用 preload API 加速文档请求(资源请求 SW 完成前先发) * - * Offline fallback:`/~offline` 路由(next.config.ts Serwist 配置里也登记了 - * `additionalPrecacheEntries`,双保险)。注意本项目目前**没实现**这个路由, - * 真要落地需要新增 src/app/~/offline/page.tsx —— 未做。 + * Offline fallback:`/~offline` 路由(serwist route handler 里也登记了 + * `additionalPrecacheEntries`,双保险)。对应页面: + * `src/app/~offline/page.tsx`。 */ import { defaultCache } from "@serwist/turbopack/worker"; import type { PrecacheEntry, SerwistGlobalConfig } from "serwist"; @@ -51,4 +51,4 @@ const serwist = new Serwist({ }, }); -serwist.addEventListeners(); \ No newline at end of file +serwist.addEventListeners(); diff --git a/src/app/~offline/page.tsx b/src/app/~offline/page.tsx new file mode 100644 index 00000000..cf412b6b --- /dev/null +++ b/src/app/~offline/page.tsx @@ -0,0 +1,84 @@ +import Link from "next/link"; + +import { ROUTES } from "@/router/routes"; + +export default function OfflinePage() { + return ( +
+
+

+ Offline +

+

+ You are offline +

+

+ Check your connection, then return to CozSweet when the network is + available again. +

+ + Back to start + +
+
+ ); +}