Mount react-admin under /admin

孤人 提交于 2021-02-19 03:37:28

问题


I simply want all of my admin pages to be under /admin.

<Admin
  title="Admin"
  dashboard={Dashboard}
  dataProvider={restClient}
  history={history}
>
  <Resource
    name="users"
    list={UserList}
  />
</Admin>

My main page is at /admin but when I click Users in the sidebar, it changes the path to /users and not /admin/users.

I'm using react-admin 2.0.0.


回答1:


The key is actually in the history prop passed to the Admin component:

import createHistory from 'history/createBrowserHistory';

const history = createHistory({ basename: '/admin' });

<Admin history={history} />



回答2:


react-router v4 expects a basename prop to arrange what you desire. More info here.

It's not clear that react-admin exposes a way for you to provide this, at least I'm not aware of one.




回答3:


We had to use nginx and host two completely different apps to do this. It does not seem easy at all to integrate react-admin with another application already using react-router. The documentation provides some help, but the documentation also is often difficult to follow so I was very trepidatious of copying and pasting it's code to try and do this.

Ovverall I've been more frustrated with react-admin the longer I use it; I think there are some great things about the project but the documentation is not well-organized, there's no easy-to-read API reference, and there are a lot of leaky abstractions in that you really have to understand the material-ui, react-final-forms, and of course react-router packages to do anything even remotely 'outside the box' with react-admin.

Sorry to vent, but, my two cents is, split the app or use a different tool.



来源:https://stackoverflow.com/questions/50402692/mount-react-admin-under-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!