diff --git a/src/router/layout/index.tsx b/src/router/layout/index.tsx index af80c6d..8eb2ad2 100644 --- a/src/router/layout/index.tsx +++ b/src/router/layout/index.tsx @@ -6,10 +6,12 @@ import { observer } from 'mobx-react'; import { useEffect } from 'react'; import store from '~/store'; import { initContract } from '~/contract'; +import { useTranslation } from 'react-i18next'; const LayoutRouter = () => { - const { location } = useRouter() + const { location, push } = useRouter() + const { i18n } = useTranslation() const { walletAddress } = store.state useEffect(() => { @@ -33,9 +35,21 @@ const LayoutRouter = () => { } }); + initLanguage() + }, []) + const initLanguage = () => { + let pathname = location.pathname.slice(1) + + if (pathname === 'zh' || pathname === 'hk' || pathname === 'en') { + i18n.changeLanguage(pathname) + push('/', null, true) + } + + } + return (