Javascript 如何在react中加载页面之前提前预加载i18n?

Javascript 如何在react中加载页面之前提前预加载i18n?,javascript,reactjs,internationalization,Javascript,Reactjs,Internationalization,我在预先预加载I18n时遇到了一个问题,因此用户无法看到应用程序的中间状态(即语言更改的实际发生方式)。 问题是,在一些请求之后,我需要更改页面语言(获取用户数据,其中提到了用户语言)。我知道通过延迟加载解决这个问题的可能方法,但这是我第一次使用它,所以如果能听到一些最佳实践,那将是非常棒的 版本是 "react": "^16.12.0", "react-dom": "^16.12.0", "react-i18next": "^11.2.7", 这就是路由结构 <Switch>

我在预先预加载I18n时遇到了一个问题,因此用户无法看到应用程序的中间状态(即语言更改的实际发生方式)。 问题是,在一些请求之后,我需要更改页面语言(获取用户数据,其中提到了用户语言)。我知道通过延迟加载解决这个问题的可能方法,但这是我第一次使用它,所以如果能听到一些最佳实践,那将是非常棒的

版本是

"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-i18next": "^11.2.7",
这就是路由结构

<Switch>
        <Route exact path={SIGNUP_PAGE} component={Signup} />
        <Route exact path={LOGIN_PAGE} component={Login} />
        <Route exact path={PASSWORD_RECOVERY} component={Recovery} />
        <Route exact path={`${NEW_PASSWORD}/:uuid?`} component={NewPassword} />
        <Route exact path={`${EMAIL_VERIFICATION}/:uuid?`} component={EmailVerification} />
        <Route exact path={SIGNUP_SUCCEED} component={SignupSucceed} />
        <MainLayout>
            <ProtectedRoutes>
                <Switch>
                    {getRoutes(routes, 'component')}
                </Switch>
            </ProtectedRoutes>
        </MainLayout>
        <Route render={() => <h1>Page not Found !!!</h1>} />
</Switch>

您应该将预加载事件添加到mouseEnter事件上的链接

i18next.loadNamespaces('anotherNamespace', (err, t) => { /* ... */ });

i18next.loadNamespaces('anotherNamespace', (err, t) => { /* ... */ });