Skip to content

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented May 24, 2023

Problem

There are rules dictating the allowed children for the Admin components because those are configuration elements. You can't just pass any react elements. This is in part because that's how React Router works when you favor JSX for your routing configuration.

This can come as a surprise for newcomers as you actually have to read the documentation to know about them.

Solution

You can now pass your resources and custom routes as objects through the admin props. This make them explicit (resources, customRoutes and customRoutesWithoutLayout) and discoverable via your IDE autocompletion.

It looks like this:

export const App = () => (
    <Admin
        dataProvider={dataProvider}
        authProvider={authProvider}
        resources={(permissions: any) => ({
            posts: {
                edit: EditGuesser,
                list: ListGuesser,
            },
            comments: {
                list: ListGuesser,
                edit: EditGuesser,
                show: ShowGuesser,
            },
        })}
        customRoutes={(permissions: any) => [
            { path: 'custom', element: <div>Custom route</div> },
        ]}
        customRoutesWithoutLayout={[
            {
                path: 'custom-no-layout',
                element: <div>Custom route no layout</div>,
            },
        ]}
    />
);

TODO

  • Implementation
  • Tests
  • Documentation

@djhi djhi added the WIP Work In Progress label May 24, 2023
Base automatically changed from next to master May 25, 2023 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work In Progress
Development

Successfully merging this pull request may close these issues.

1 participant