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运行高引起的 可以查看手机的崩溃日 ...
随机推荐
- keystone同步数据库的时候提示error
keystone 在同步的时候报出以下错误: su -s /bin/sh -c "keystone-manage db_sync" keystone CRITICAL keysto ...
- 使用php simple html dom parser解析html标签
转自:http://www.blhere.com/1243.html 使用php simple html dom parser解析html标签 用了一下 PHP Simple HTML DOM Par ...
- Map容器案例
案例讲解 --统计字符串出现的次数 package com.date; import java.util.HashMap; import java.util.Map; import java.uti ...
- windows下多版本python安装与pip安装和pip使用 吐血总结
https://blog.csdn.net/silence2015/article/details/56483892/ 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十四章:曲面细分阶段
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十四章:曲面细分阶段 代码工程地址: https://github. ...
- php 正则学习取反符号~
php 正则学习取反符号~ ~(<a .*?>.*?</a>|<.*?>)~i 先看正则图形,有点偏差,但可以初步看出结果. 关于 ~ 是取反符号,看下面说明.
- python的if循环和嵌套
1. if 条件: if语句块 执行流程:判断条件是否为真. 如果真. 执行if语句块 money = int(input('请输入你兜里的钱:')) if money >500 ...
- 2019-8-31-dotnet-通过-WMI-获取系统补丁
title author date CreateTime categories dotnet 通过 WMI 获取系统补丁 lindexi 2019-08-31 16:55:59 +0800 2019- ...
- [ Laravel 5.6 文档 ] 安全系列 —— 重置密码
http://laravelacademy.org/post/8929.html 简介 想要快速实现该功能?只需要在新安装的 Laravel 应用下运行 php artisan make:auth(如 ...
- oracle不明确的索引等级
当ORACLE无法判断索引的等级高低差别,优化器将只使用一个索引,它就是在WHERE子句中被列在最前面的. 举例: DEPTNO上有一个非唯一性索引,EMP_CAT也有一个非唯一性索引. SELECT ...