ALIEZ 1 tháng trước cách đây
mục cha
commit
3d37ff4669
2 tập tin đã thay đổi với 13 bổ sung11 xóa
  1. 13 0
      next.config.ts
  2. 0 11
      src/app/page.tsx

+ 13 - 0
next.config.ts

@@ -18,6 +18,19 @@ const nextConfig: NextConfig = {
   experimental: {
     trustHostHeader: true,
   } as NextConfig["experimental"],
+  /**
+   * 必须在配置层做根路径重定向:`app/page.tsx` + permanentRedirect 会被预渲染为静态 ○ /,
+   * 线上容易出现「必须手输 /zh」;redirects 在路由层优先匹配,且 destination 为相对路径,不会错写成 :3000。
+   */
+  async redirects() {
+    return [
+      {
+        source: "/",
+        destination: "/zh",
+        permanent: true,
+      },
+    ];
+  },
   async rewrites() {
     const rewrites = [];
     if (apiProxyTarget && /^https?:\/\//i.test(apiProxyTarget)) {

+ 0 - 11
src/app/page.tsx

@@ -1,11 +0,0 @@
-import { permanentRedirect } from "next/navigation";
-
-import { routing } from "@/i18n/routing";
-
-/**
- * 根路径无 [locale] 段时,部分部署下 Proxy/Middleware 对 `/` 未命中会 404。
- * 此处兜底跳转到默认语言(与 next-intl `localePrefix: "always"` 一致)。
- */
-export default function RootPage() {
-  permanentRedirect(`/${routing.defaultLocale}`);
-}