我将react admin与API Platform admin一起使用,但我不知道为什么在生产中会出现此错误,但在本地docker环境中却没有:
react-dom.production.min.js:3282
TypeError: Cannot read property 'filter' of undefined
at l (fieldFactory.js:21)
at p (List.js:83)
at beginWork (react-dom.production.min.js:2902)
at o (react-dom.production.min.js:4051)
at a (react-dom.production.min.js:4068)
at x (react-dom.production.min.js:4296)
at w (react-dom.production.min.js:4263)
at b (react-dom.production.min.js:4254)
at interactiveUpdates (react-dom.production.min.js:4563)
at xn (react-dom.production.min.js:1684)
我正在使用demo example,不知道是哪个元素导致了此问题:是否有办法知道哪个元素导致了错误?
答案 0 :(得分:1)
原来的错误是我错误地提供了in the demo所示的自定义路由,然后使用API平台的authentication example来设置这些自定义路由:
switch (result.status) {
case 401:
return Promise.resolve({
api: result.api,
customRoutes: [{
props: {
path: '/',
render: () => <Redirect to={`/login`}/>,
},
}],
});
default:
return Promise.reject(result);
}
...
<HydraAdmin
title=""
dataProvider={dataProvider}
customReducers={{ theme: themeReducer }}
customSagas={sagas}
customRoutes={customRoutes}
authProvider={authProvider}
dashboard={Dashboard}
loginPage={Login}
appLayout={Layout}
menu={Menu}
locale="en"
i18nProvider={i18nProvider}
>
...
向API平台提供错误的路由会触发该错误。因此我通过删除自定义路由来解决它:customRoutes={customRoutes}