Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React路由器错误无法读取属性';forEach&x27;未定义的_Reactjs_React Router - Fatal编程技术网

Reactjs React路由器错误无法读取属性';forEach&x27;未定义的

Reactjs React路由器错误无法读取属性';forEach&x27;未定义的,reactjs,react-router,Reactjs,React Router,将react从版本15更新到版本16时,我遇到以下错误: 无法读取PrivateRoute组件中未定义的属性“forEach” 包JSON显示了这些版本: "react": "^16.10.1", "react-dom": "^16.10.1", "react-router": "^5.1.1", "react-router-dom": "^5.1.1", "react-router-redux": "*" 下面是要查看的组件代码: 我试图安装eslint和eslint loader,因为我发

将react从版本15更新到版本16时,我遇到以下错误:

无法读取PrivateRoute组件中未定义的属性“forEach”

包JSON显示了这些版本:

"react": "^16.10.1",
"react-dom": "^16.10.1",
"react-router": "^5.1.1",
"react-router-dom": "^5.1.1",
"react-router-redux": "*"
下面是要查看的组件代码:

我试图安装eslint和eslint loader,因为我发现这可能是问题所在,但运气不好

import React from "react";
import { Route, Redirect } from "react-router-dom";

const PrivateRoute = ({
    component: Component,
    Authenticated,
    AdminPage,
    Admin,
    ...props
}) => (
    <Route
        {...props}
        render={props => {
            if (AdminPage) {
                if (Authenticated && Admin) {
                    return <Component {...props} />;
                } else {
                    return (
                        <Redirect
                            to={{
                                pathname: "/",
                                state: { from: props.location }
                            }}
                        />
                    );
                }
            } else {
                if (Authenticated) {
                    return <Component {...props} />;
                } else {
                    return (
                        <Redirect
                            to={{
                                pathname: "/login",
                                state: { from: props.location }
                            }}
                        />
                    );
                }
            }
        }}
    />
);

export default PrivateRoute;


从“React”导入React;
从“react router dom”导入{Route,Redirect};
const privaterote=({
组件:组件,
认证,
AdminPage,
管理
…道具
}) => (
{
如果(管理页面){
如果(已验证和管理){
返回;
}否则{
返回(
);
}
}否则{
如果(已验证){
返回;
}否则{
返回(
);
}
}
}}
/>
);
导出默认私有路由;

以下是一些可以尝试的东西:

  • 将react脚本降级为3.0.1
  • 从devdependency中删除eslint
  • 删除package-lock.json,删除node_模块,运行npm安装
如果使用纱线,还可以将其添加到package.json:

"resolutions": {
    "eslint-loader": "3.0.2"
}
更多信息,请访问:
(错误报告)

您能提供一个可复制的示例吗?您可以在CodeSandbox上轻松创建一个。package.json中的react脚本版本是什么?如果您的react脚本版本大于3.0.1,则可以尝试两个选项,如果您的react脚本版本大于3.0.1,则降级到3.0.1,如果不是,则删除node_模块和package-lock.json文件并重新安装node_模块,可能会解决此错误react脚本位于3.1.2。现在我将尝试降级到3.0.1,并检查运气。同样的错误再次出现。