next-i18next 常见Bug记录
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服务器
- 更改exportPathMap配置使带有语言前缀的路径可以正常刷新定向
- 在next钩子_app.js中render之前去检测当前Router路径得以判断出当前应该changeLanguage哪种语言
- 封装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记录的更多相关文章
- IE6的那些css常见bug(汇总)
IE6的那些css常见bug(汇总) 我的微博终于在前几天建立了 虽说很早之前就知道博客园这个地方 但怕自己不能坚持去写一些东西一直没有建.这几天 我做了这个决定 把我的博客建起来 每周发一些看到的, ...
- 我的第一篇文章 —— IE6的那些css常见bug(汇总)
我的微博终于在前几天建立了 虽说很早之前就知道博客园这个地方 但怕自己不能坚持去写一些东西一直没有建.这几天 我做了这个决定 把我的博客建起来 每周发一些看到的,听到了一些前端知识或者前沿技术. 另外 ...
- ie7,8常见bug,共计257个bug汇总?如何解决ie的历史bug
ie7.8常见bug,共计257个bug汇总 针对web开发者来说,浏览器的bug,特备是ie的bug是很多人的噩梦,因为ie的更新换代没有ff,chrome,safari,opera那么快,而且ie ...
- CSS控制之IE常见BUG及解决方案
常见bug 解决方案 盒模型bug 使用严格doctype声明 双倍margin bug _display:inline; 不认识a:link 不加:link 3像素margin bug 规范浮动与清 ...
- 【bug记录】OS Lab3 踩坑记
OS Lab3 踩坑记 Lab3在之前Lab2的基础上,增加了进程建立.调度和中断异常处理.其中测试包括进程建立以及进程调度部分. 由于是第一次做bug记录,而且是调试完bug后再做的记录,所以导致记 ...
- 微信小程序bug记录与解决
微信小程序bug记录 textarea textarea在模拟器上没有padding,可是在真机上会自带padding,而且在外部改不了,并且在安卓和IOS上padding还不一样 第一张图是在开发工 ...
- 微信网页跳转页面常见bug处理
微信网页跳转页面常见bug处理 1.不要直接用a链接直接跳转 2.url后加上时间戳 function gohome() { window.location.href = "../home/ ...
- IE6中CSS常见BUG全集及解决方案——摘自网友
IE6中CSS常见BUG全集及解决方案 IE6双倍边距bug 当页面内有多个连续浮动时,如本页的图标列表是采用左浮动,此时设置li的左侧margin值时,在最左侧呈现双倍情况.如外边距设置为10px, ...
- 常见bug解析-移动端
手机测试常见bug解析 1.测试时遇到“手机无响应”? 有以下几个原因: a.手机内存不足 b.android进程之间死锁引起的(就是两个进程之间) c.手机的CPU运行高引起的 可以查看手机的崩溃日 ...
随机推荐
- oracle-ORA-01567错误
删除日志4时将在线索1中保留少于两个日志文件
- twitter、facebook、pinterest、linkedin 分享代码
twitter.facebook.pinterest.linkedin 分享代码 http://www.cnblogs.com/adstor-Lin/p/3994449.html
- JavaScript —— 给函数参数设置默认值
一.ES5 function fn(x, y){ y = y || 20; console.log(x, y); } fn(); // undefined 20 fn(5); // 5 20 fn(5 ...
- Linux使用及命令
#命令模式下输入:光标移动到第34行第15个字符 <Enter>15l(这是小写的L) ctrl+u删除光标前面的字符 ctrl+j删除光标后面的字符 在Linux下用VIM打开大小几个G ...
- @codeforces - 1209H@ Moving Walkways
目录 @description@ @solution@ @accepted code@ @details@ @description@ 机场中常常见到滑行道:假如一个滑行道的运行速度为 s,你的行走速 ...
- 洛谷P1910 L国的战斗之间谍
//二维费用01背包 #include<bits/stdc++.h> using namespace std; ; ; ; int v1[maxn],v2[maxn],w[maxn],n, ...
- vue filter使用方法
Vue.js 允许你自定义过滤器,可被用于一些常见的文本格式化. 过滤器可以用在两个地方:双花括号插值和 v-bind 表达式 (后者从 2.1.0+ 开始支持). 过滤器应该被添加在 JavaScr ...
- WPS修订功能的使用
WPS设置 设置用户名: 修改之后的效果:
- 唯一索引与非唯一索引区别(UNIQUE INDEX, NON-UNIQUE INDEX)
索引是我们经常使用的一种数据库搜索优化手段.适当的业务操作场景使用适当的索引方案可以显著的提升系统整体性能和用户体验.在Oracle中,索引有包括很多类型.不同类型的索引适应不同的系统环境和访问场景. ...
- 十分钟学会 Fiddler
一.Fiddler介绍 Fiddler是一个http抓包改包工具,fiddle英文中有"欺骗.伪造"之意,与wireshark相比它更轻量级,上手简单,因为只能抓http和http ...