小编Tar*_*rei的帖子

如何修复未捕获的 DOMException:无法在“历史记录”上执行“pushState”

我有这个小应用程序在 webpack-dev-server 的开发模式下运行良好,但是当我使用生产模式生成的 dist 文件夹中的捆绑文件时,我在浏览器中得到的只是这个错误:

Uncaught DOMException: Failed to execute 'pushState' on 'History': A history state object with URL 'file:///C:/' cannot be created in a document with origin 'null' and URL 'file:///C:/Users/cristi/work/react_test_ground/dist/index.html'.
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个 pushState 问题?

最初我尝试用 React.lazy 和 Suspense 拆分代码,因为 webpack 抛出了这个错误:

WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
This can impact web performance.
Assets:
  2c7b7b6becb423b8f2ae.bundle.js (413 KiB)

WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended …
Run Code Online (Sandbox Code Playgroud)

reactjs react-router webpack-4

10
推荐指数
2
解决办法
1万
查看次数

我想将嵌套数组的数字加在一起

这就是我想出的:

var nestedArr = [[[1,2],[3,4]],[[5,6]]];

function sumTotal() {
	for(var i = 0; i < nestedArr.length; i++) {
		for(var j = 0; j < nestedArr[i].length; j++) {
			for(var k = 0; k < nestedArr[i][j].length; k++) {
				var arrNumSum = nestedArr[i][j][k]; 
				arrNumSum += arrNumSum;

				return arrNumSum; 		
			}
		}
	}	
}

sumTotal();
Run Code Online (Sandbox Code Playgroud)

javascript

0
推荐指数
1
解决办法
62
查看次数

如何更改 react-toastify 弹出消息的样式?

我想将我自己的自定义样式添加到 react-toastify 消息弹出窗口,具体取决于它是成功还是错误。到目前为止,我尝试了以下方法:

toastify.js

import { toast, Slide } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import { css } from "glamor";


toast.configure({
    position: toast.POSITION.BOTTOM_RIGHT,
    autoClose: 3000,
    transition: Slide,
    pauseOnFocusLoss: false,
        className: css({
        backgroundColor: 'red',
    }),
    bodyClassName: css({
        backgroundColor: 'blue',
        height: '100%',
        width: '100%',
    })
});

export default function (message, type, styles = {}) {
    switch (type) {
        case type === 'success':
            toast.success(message);
            break;

        case type === 'error':
            toast.error(message);
            break;

        case type === 'info':
            toast.info(message);
            break;

        case type === 'warn':
            toast.warn(message);
            break;
            
        default: …
Run Code Online (Sandbox Code Playgroud)

reactjs react-toastify

0
推荐指数
2
解决办法
6893
查看次数