我来寻求你的帮助。事实上,我正在使用 api 平台与 Symfony 一起开发 api。但是,当我想使用 api platform/admin 和 react-admin 生成管理界面时,我在控制台中收到此错误。
@api-platform_admin.js?v=5df60b07:115027 Uncaught TypeError: Cannot read properties of undefined (reading 'mode')
at ToggleThemeLegacyButton (@api-platform_admin.js?v=5df60b07:115027:97)
at renderWithHooks (chunk-KXIZOLV7.js?v=5df60b07:12169:26)
at mountIndeterminateComponent (chunk-KXIZOLV7.js?v=5df60b07:14919:21)
at beginWork (chunk-KXIZOLV7.js?v=5df60b07:15900:22)
at HTMLUnknownElement.callCallback2 (chunk-KXIZOLV7.js?v=5df60b07:3672:22)
at Object.invokeGuardedCallbackDev (chunk-KXIZOLV7.js?v=5df60b07:3697:24)
at invokeGuardedCallback (chunk-KXIZOLV7.js?v=5df60b07:3731:39)
at beginWork$1 (chunk-KXIZOLV7.js?v=5df60b07:19759:15)
at performUnitOfWork (chunk-KXIZOLV7.js?v=5df60b07:19192:20)
at workLoopSync (chunk-KXIZOLV7.js?v=5df60b07:19131:13)
这是我的 App.tsx 文件
import { HydraAdmin } from "@api-platform/admin";
export const App = () => (
<HydraAdmin entrypoint="http://localhost:8000/api" >
</HydraAdmin>
);
我一遍又一遍地关注api平台文档中的内容,但无济于事。 如果社区可以帮助我解决这个问题。谢谢你。
我找到了解决方案。
ToggleThemeLegacyButton 类中存在错误。如果你查看它的文档,你会发现它已被弃用。为了避免这个问题,你必须显式传递 lightTheme 和 darkTheme 属性。这是我的 App.js:
import { defaultTheme } from 'react-admin';
import { HydraAdmin, OpenApiAdmin } from '@api-platform/admin'
const lightTheme = defaultTheme;
const darkTheme = { ...defaultTheme, palette: { mode: 'dark' } };
// export default () => <HydraAdmin
// theme={lightTheme}
// darkTheme={darkTheme}
// entrypoint="http://127.0.0.1:8000/api" />;
export default () => <OpenApiAdmin
docEntrypoint="http://127.0.0.1:8000/api/docs.jsonopenapi"
entrypoint="http://127.0.0.1:8000/api/admin"
theme={lightTheme}
darkTheme={darkTheme}
/>;