从15版本更新到16版本时,我收到此错误:
无法读取PrivateRoute组件中未定义的属性“ forEach”。
Package 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;
答案 0 :(得分:1)
以下是一些可以尝试的东西:
如果使用yarn,也可以将其添加到package.json:
"resolutions": {
"eslint-loader": "3.0.2"
}
更多信息,请访问: https://github.com/facebook/create-react-app/issues/7753 (错误报告)