Browse Source

添加通过路径切换语言

master
yyy 6 months ago
parent
commit
6308cbc2e4
  1. 16
      src/router/layout/index.tsx

16
src/router/layout/index.tsx

@ -6,10 +6,12 @@ import { observer } from 'mobx-react';
import { useEffect } from 'react'; import { useEffect } from 'react';
import store from '~/store'; import store from '~/store';
import { initContract } from '~/contract'; import { initContract } from '~/contract';
import { useTranslation } from 'react-i18next';
const LayoutRouter = () => { const LayoutRouter = () => {
const { location } = useRouter()
const { location, push } = useRouter()
const { i18n } = useTranslation()
const { walletAddress } = store.state const { walletAddress } = store.state
useEffect(() => { 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 ( return (
<div className='layout'> <div className='layout'>
<Navbar <Navbar

Loading…
Cancel
Save