next.js - 如何避免 Next.js 中出现“You have not declared a namespacesRequired array”错误?
问题描述
我将该next-i18next
模块用于多语言应用程序。我不明白为什么会出现以下错误,因为我已经按照文档中显示的方式声明了命名空间。
错误信息:
You have not declared a namespacesRequired array on your page-level component: Home.
This will cause all namespaces to be sent down to the client, possibly negatively impacting the performance of your app.
For more info, see: https://github.com/isaachinman/next-i18next#4-declaring-namespace-dependencies
索引.ts
import Head from 'next/head'
import styles from '../styles/Home.module.css'
import { withTranslation } from '../i18n'
import { useTranslation } from 'react-i18next';
// import NextI18NextInstance from '../i18n';
function Home({ coursesData }) {
const { t, i18n } = useTranslation(['common', 'cars']);
return (
<>
<h1>{t('common:indexHeader')}</h1>
<h2>{t('cars:title')}</h2>
</>
)
}
// All works with this code, but I plan to use getServerSideProps()
// Home.getInitialProps = async () => {
// return {
// namespacesRequired: ['common', 'courses']
// }
// }
export default Home
我该如何解决这个问题?
解决方案
next-i18next
尚不支持getServerProps
,因此您需要继续使用getInitialProps
.
欲了解更多信息:https ://github.com/isaachinman/next-i18next/issues/652
推荐阅读
- haskell - 从 IO Monad 设置配置参数 - 设计模式
- c - 将字符数组转换为结构类型
- node.js - 使用 fetch 抓取网页 - 承诺无法解决
- reactjs - 无法在 React 上使用 Multer 上传多个文件
- vue.js - 我如何拥有一个 Chart.vue 组件而不是不同的图表组件,然后通过更改 API 的 ID 来显示图表
- html - Flexbox:不能在容器项目上使用空格
- android - Windows 10 上的 Android Studio 4.1.1“无法访问 android.app.Activity”
- java - 在 Android API 22 Java 8 中使用带有 log4j 2.7 的 maven jar 获取 java.lang.NullPointerException:尝试获取空数组的长度
- php - 我有一个非常不稳定的多站点 wordpress
- android-studio - 我在flutter中创建新应用程序,在vs代码终端中创建AppName它工作但是当我尝试flutter run时它显示这个错误消息