Closed zhengjunxiang closed 1 year ago
I use useChangeLocale to change locale when set the urlMappingStrategy: 'rewrite', and the url is start with locale
// middleware.ts import { createI18nMiddleware } from 'next-international/middleware'; import { NextRequest } from 'next/server'; const I18nMiddleware = createI18nMiddleware(['en', 'zh'] as const, 'zh', { urlMappingStrategy: 'rewrite' }); export function middleware(request: NextRequest) { return I18nMiddleware(request); } export const config = { matcher: ['/((?!api|image|_next/static|_next/image|favicon.ico).*)'] };
import { useCurrentLocale, useI18n, useChangeLocale } from '@/locales/client'; export default function Switch() { const locale = useCurrentLocale(); const changeLocale = useChangeLocale() const handleChangeLanguage = () => { changeLocale(locale === 'zh' ? 'en' : 'zh') } const items: MenuProps['items'] = [ { key: '1', label: ( <div onClick={handleChangeLanguage}> { locale === 'en' ? t('zh') : t('en') } </div> ), } ]; return ( <div className="text-base leading-8"> <Dropdown menu={{ items }}> <div className='cursor-pointer flex items-center'> { locale === 'zh' ? t('zh') : t('en') } <DownOutlined /> </div> </Dropdown> </div> ); }
I hope the url doesn't include a locale, thinks
Thanks, I've released 0.9.3 which includes #137 and that should fix your issue. Feel free to open another issue if it's not the case!
I use useChangeLocale to change locale when set the urlMappingStrategy: 'rewrite', and the url is start with locale
I hope the url doesn't include a locale, thinks