12

I am using react-admin previously admin-on-rest. I want to create a custom page that doesn't show the Menu sidebar, like Login page. I will use this page reset user's password. How can I do that?

Mário Ferreiro
  • 317
  • 3
  • 12
thecassion
  • 506
  • 1
  • 7
  • 19

4 Answers4

21

This is not obvious in the documentation but the Route actually accepts a noLayout prop:

<Admin
    customRoutes={[
        <Route
            path="/custom"
            component={CustomRouteNoLayout}
            noLayout
        />,
        <Route
            path="/custom2"
            component={CustomRouteWithLayout}
        />,
    ]}
>
Gildas Garcia
  • 6,966
  • 3
  • 15
  • 29
  • v4 now has the following in their documentation: ```Tip: In previous versions of react-admin, you had to write instead of . The former still works in Js projects but TypeScript won’t compile it.``` So you need to change that unless you are using .js – Valera Tumash Feb 06 '22 at 09:29
3

Add a custom route with the component you want to render. When route is successful the specified component will be presented. No Menu will be shown just whatever you have in the component you send as prop to Route.

The way you put the question it seemed like you were trying to have a custom page that hadn't a MenuItemLink in Menu. Had to reread the question to understand what you wanted.

Mário Ferreiro
  • 317
  • 3
  • 12
2

I'd like to add on to Gildas Garcia's answer. After you added the customed routes as shown in the documentation, you need to add a hash # in front of the route url to be able to view the content. For example, if you are displaying the view at localhost:3000/, and one of your routes is

<Route exact path="/foo" component={Foo} />,

then you should go to localhost:3000/#/foo to view the content.

Darius
  • 441
  • 1
  • 5
  • 13
0

As per current documentation (v4.12.1) you can use the noLayout property available in the CustomRoutes component:

const App = () => (
    <Admin dataProvider={dataProvider}>
        <CustomRoutes noLayout>
            <Route path="/register" element={<Register />} />
        </CustomRoutes>
        <CustomRoutes>
            <Route path="/settings" element={<Settings />} />
            <Route path="/profile" element={<Profile />} />
        </CustomRoutes>
    </Admin>
);
sergioruizsan
  • 86
  • 1
  • 7