This is an automated email from the ASF dual-hosted git repository.
dengliming pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shenyu-website.git
The following commit(s) were added to refs/heads/main by this push:
new 8898863171 [type:feature] auto redirect url when detect browser
language (#769)
8898863171 is described below
commit 889886317145874b2c0f2a74f2d09e4de6e600a8
Author: tomsun28 <[email protected]>
AuthorDate: Fri Sep 30 11:52:17 2022 +0800
[type:feature] auto redirect url when detect browser language (#769)
---
src/pages/index.tsx | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 392691c991..cfc72bc595 100755
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -1,4 +1,4 @@
-import React from "react";
+import React, {useEffect} from "react";
import Link from "@docusaurus/Link";
import Translate, { translate } from "@docusaurus/Translate";
import { Swiper, SwiperSlide } from "swiper/react";
@@ -26,6 +26,8 @@ function Home() {
tagline,
},
} = useDocusaurusContext();
+ useEffect(() => autoRedirect(), []);
+
return (
<Layout title={tagline} description={description as string}>
<main>
@@ -162,4 +164,15 @@ function Home() {
);
}
+function autoRedirect() {
+ let lang = global.navigator?.language || navigator?.language
+ if (lang != null && lang.toLowerCase() === 'zh-cn') {
+ if (sessionStorage.getItem('auto_detect_redirect') !== 'true') {
+ console.log('Current lang is ' + lang);
+ sessionStorage.setItem('auto_detect_redirect', 'true')
+ window.location.href = '/zh/';
+ }
+ }
+}
+
export default Home;