瀏覽代碼

fix: locale match error (#115)

Joel 1 年之前
父節點
當前提交
96809108ca
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      web/middleware.ts

+ 5 - 1
web/middleware.ts

@@ -23,7 +23,11 @@ export const getLocale = (request: NextRequest): Locale => {
   }
 
   // match locale
-  const matchedLocale = match(languages, locales, i18n.defaultLocale) as Locale
+  let matchedLocale:Locale  = i18n.defaultLocale
+  try {
+    // If languages is ['*'], Error would happen in match function.
+    matchedLocale = match(languages, locales, i18n.defaultLocale) as Locale
+  } catch(e) {}
   return matchedLocale
 }