TypeError: Cannot read property 'wait' of null

此处根本原因为next版本(使用withNamespaces导入命名空间报错)
^5.0.0版本不支持导入_app.js导致i18n注入失败
^6.0.0版本或者以上版本会支持导入_app.js
尝试更新withNamespaces的wait和options并没有效果,相反会导致之后的一系列bug
此处使用next-i18next步骤链接: [next-i18next].
附上react-i18next的链接: [react-i18next].
附上i18next的链接: [i18next].
附上语言转换操作技巧:使用translate-components插件可以通过node命令进行生成对应json文件,然后根据需要进行转换即可

You have not declared a namespacesRequired array on your page-level component

此处在页面级组件不导入namespacesRequired命名空间组或者在static下的locales有未引用的json都会报这个警告

nexti18next FrontWebsite Router Options

此处如果next没有版本限制并且可以使后台支持最好的办法是使用官方文档推荐做法
此方案适用于因后台无法提供支持且无法使用pm2服务器

  1. 更改exportPathMap配置使带有语言前缀的路径可以正常刷新定向
  2. 在next钩子_app.js中render之前去检测当前Router路径得以判断出当前应该changeLanguage哪种语言
  3. 封装next/link next/router以使前端的路由定向正常

以下附上代码方案

/**************************************
--------------_app.js--------------
**************************************/
import React from 'react'
import App, { Container } from 'next/app'
import { i18n, appWithTranslation } from '../i18n' class MyApp extends App {
// static async getInitialProps({ Component, ctx }) {
// // const language = ctx ? ctx.req.headers['accept-language'] : (navigator.language || navigator.browserLanguage).toLowerCase()
// let pageProps = {}
//
// if (Component.getInitialProps) {
// pageProps = await Component.getInitialProps(ctx)
// }
//
// return { pageProps }
// }
render() {
const { Component, pageProps } = this.props
// console.log(this.props)
const languageUrl = this.props.router.asPath.replace(/\//g, '').substr(0, 2)
const languages = ['zh', 'th']
const language = ~languages.indexOf(languageUrl) ? languageUrl : languages[0]
i18n.changeLanguage(language)
return (
<Container>
<Component {...pageProps} />
</Container>
)
}
} export default appWithTranslation(MyApp) /**************************************
--------------Link---------------
**************************************/
import React from 'react'
import NextLink from 'next/link'
import { i18n } from '../../i18n' class Link extends React.Component {
render () {
const {
as,
href,
children,
...props
} = this.props; return React.createElement(NextLink, {
href: href,
as: `/${i18n.language}${href}`
}, children);
}
} export default Link /**************************************
------------Router-------------
**************************************/
import NextRouter from 'next/router';
import { i18n } from '../../i18n'
const propertyFields = ['pathname', 'router', 'query', 'asPath', 'components', 'events'];
const coreMethods = ['reload', 'back', 'beforePopState', 'ready', 'prefetch'];
const wrappedMethods = ['push', 'replace']; const Router = {};
propertyFields.forEach(field => {
Object.defineProperty(Router, field, {
get() {
return NextRouter[field];
}
});
});
coreMethods.forEach(method => {
Router[method] = (...args) => NextRouter[method](...args);
});
wrappedMethods.forEach(method => {
Router[method] = (path, as, options) => {
return NextRouter[method](path, `/${i18n.language}${path}`, options);
};
}); export default Router;

next-i18next 常见Bug记录的更多相关文章

  1. IE6的那些css常见bug(汇总)

    IE6的那些css常见bug(汇总) 我的微博终于在前几天建立了 虽说很早之前就知道博客园这个地方 但怕自己不能坚持去写一些东西一直没有建.这几天 我做了这个决定 把我的博客建起来 每周发一些看到的, ...

  2. 我的第一篇文章 —— IE6的那些css常见bug(汇总)

    我的微博终于在前几天建立了 虽说很早之前就知道博客园这个地方 但怕自己不能坚持去写一些东西一直没有建.这几天 我做了这个决定 把我的博客建起来 每周发一些看到的,听到了一些前端知识或者前沿技术. 另外 ...

  3. ie7,8常见bug,共计257个bug汇总?如何解决ie的历史bug

    ie7.8常见bug,共计257个bug汇总 针对web开发者来说,浏览器的bug,特备是ie的bug是很多人的噩梦,因为ie的更新换代没有ff,chrome,safari,opera那么快,而且ie ...

  4. CSS控制之IE常见BUG及解决方案

    常见bug 解决方案 盒模型bug 使用严格doctype声明 双倍margin bug _display:inline; 不认识a:link 不加:link 3像素margin bug 规范浮动与清 ...

  5. 【bug记录】OS Lab3 踩坑记

    OS Lab3 踩坑记 Lab3在之前Lab2的基础上,增加了进程建立.调度和中断异常处理.其中测试包括进程建立以及进程调度部分. 由于是第一次做bug记录,而且是调试完bug后再做的记录,所以导致记 ...

  6. 微信小程序bug记录与解决

    微信小程序bug记录 textarea textarea在模拟器上没有padding,可是在真机上会自带padding,而且在外部改不了,并且在安卓和IOS上padding还不一样 第一张图是在开发工 ...

  7. 微信网页跳转页面常见bug处理

    微信网页跳转页面常见bug处理 1.不要直接用a链接直接跳转 2.url后加上时间戳 function gohome() { window.location.href = "../home/ ...

  8. IE6中CSS常见BUG全集及解决方案——摘自网友

    IE6中CSS常见BUG全集及解决方案 IE6双倍边距bug 当页面内有多个连续浮动时,如本页的图标列表是采用左浮动,此时设置li的左侧margin值时,在最左侧呈现双倍情况.如外边距设置为10px, ...

  9. 常见bug解析-移动端

    手机测试常见bug解析 1.测试时遇到“手机无响应”? 有以下几个原因: a.手机内存不足 b.android进程之间死锁引起的(就是两个进程之间) c.手机的CPU运行高引起的 可以查看手机的崩溃日 ...

随机推荐

  1. qbao

    # -*- coding: utf-8 -*- import Image, cStringIO, webbrowser, re, time, math import urllib, urllib2, ...

  2. bzoj1877 晨跑

    Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他 坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个 ...

  3. hdu2176 尼姆博弈

    如果 a1^a2^a3........^an=0,必败态. 如果 a1^a2^a3........^an!=0,必胜态. 对于必胜态,若a1^a2^a3........^an=k,要让对方为必败态,所 ...

  4. MySQL命令行分号无法结束问题解决

    背景:输入一串查询语句,以分号结束,发现没有结束,再打回车,分号,还是不完.什么exit,quit,bye,都不顶用如果要ctrl+C吧,又得退出mysql,一切重来,很麻烦.后来终于发现,引起这种现 ...

  5. 关于Apple Watch,听听开发了两个月Watch App的工程师怎么说

    今年1月份有幸应苹果邀请,秘密参与苹果 Watch App 的真机现场调试.4月份,Apple Watch 会正式上市.在这之前,也算是亲自抢先体验了 Apple Watch,以及开发了一下 Watc ...

  6. UVA_488:Triangle Wave

    PS:The input begins with a single positive integer on a line by itself indicating the number of the ...

  7. [React Native]StatusBar的使用

    StatusBar是React Native 0.20 新增的跨平台组件,它可以用来设置并动态改变设备的状态栏显示特性. 虽然说是跨平台的组件, 但是有些属性不是跨平台的 ,我们需要注意下.因为IOS ...

  8. 巨蟒python全栈开发-第11阶段 ansible_project3

    今日大纲: 1.用户创建 2.前端优化 3.用户编辑 4.用户删除 5.ansible api介绍 1.用户创建 新建一个user_create.html的页面 <form class=&quo ...

  9. iOS 设计

    APP引导页设计经验分享 http://www.cocoachina.com/design/20150615/12126.html 获取app安装的进度,6种不同的加载指示 http://www.co ...

  10. python while 循环结构