You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -330,17 +337,18 @@ The Auth Provider also lets you configure redirections after login/logout, anony
330
337
331
338
## `basename`
332
339
333
-
Use this prop to make all routes and links in your Admin relative to a "base" portion of the URL pathname that they all share. This is required when using the [`BrowserHistory`](https://github.com/remix-run/history/blob/main/docs/api-reference.md#createbrowserhistory) to serve the application under a sub-path of your domain (for example https://marmelab.com/ra-enterprise-demo), or when embedding react-admin inside a single-page app with its own routing.
340
+
Use this prop to make all routes and links in your Admin relative to a "base" portion of the URL pathname that they all share. This is required when using the [`BrowserRouter`](https://reactrouter.com/en/main/router-components/browser-router) to serve the application under a sub-path of your domain (for example https://marmelab.com/ra-enterprise-demo), or when embedding react-admin inside a single-page app with its own routing.
334
341
335
342
```tsx
336
343
import { Admin } from'react-admin';
337
-
import { createBrowserHistory } from'history';
344
+
import { BrowserRouter } from'react-router-dom';
338
345
339
-
const history =createBrowserHistory();
340
346
const App = () => (
341
-
<Adminbasename="/admin"history={history}>
342
-
...
343
-
</Admin>
347
+
<BrowserRouter>
348
+
<Adminbasename="/admin">
349
+
...
350
+
</Admin>
351
+
</BrowserRouter>
344
352
);
345
353
```
346
354
@@ -434,6 +442,7 @@ If you want to support both light and dark mode, you can provide a `darkTheme` i
434
442
435
443
```tsx
436
444
import { Admin } from'react-admin';
445
+
import { dataProvider } from'./dataProvider';
437
446
import { darkTheme, lightTheme } from'./themes';
438
447
439
448
const App = () => (
@@ -482,11 +491,11 @@ You can opt out of telemetry by simply adding `disableTelemetry` to the `<Admin>
@@ -572,10 +581,17 @@ Finally, you can also pass a custom component as the `layout` prop. It must cont
572
581
If you want to customize the Login page, or switch to another authentication strategy than a username/password form, pass a component of your own as the `loginPage` prop. React-admin will display this component whenever the `/login` route is called.
573
582
574
583
```tsx
584
+
import { Admin } from'react-admin';
585
+
import { dataProvider } from'./dataProvider';
586
+
import { authProvider } from'./authProvider';
575
587
importMyLoginPagefrom'./MyLoginPage';
576
588
577
589
const App = () => (
578
-
<AdminloginPage={MyLoginPage}>
590
+
<Admin
591
+
loginPage={MyLoginPage}
592
+
authProvider={authProvider}
593
+
dataProvider={dataProvider}
594
+
>
579
595
...
580
596
</Admin>
581
597
);
@@ -737,9 +753,17 @@ Some pages in react-admin apps may allow anonymous access. For that reason, reac
737
753
If you know your app will never accept anonymous access, you can force the app to wait for the `authProvider.checkAuth()` to resolve before rendering the page layout, by setting the `<Admin requireAuth>` prop.
The `<Admin>` component initializes a [Store](./Store.md) for user preferences using `localStorage` as the storage engine. You can override this by passing a custom `store` prop.
750
774
751
-
For instance, you can store the data in memory instead of `localStorage`. This is useful e.g. for tests, or for apps that should not persist user data between sessions:
775
+
Built-in stores are:
776
+
777
+
-`memoryStore`: stores data in memory
778
+
-`localStorageStore`: stores data in `localStorage`
779
+
780
+
For instance, you can store the user preferences in memory, e.g. for tests, or for apps that should not persist user data between sessions:
React-admin links are absolute (e.g. `/posts/123/show`). If you serve your admin from a sub path (e.g. `/admin`), react-admin works seamlessly as it only appends a hash (URLs will look like `/admin#/posts/123/show`).
856
885
857
-
However, if you serve your admin from a sub path AND use another Router (like `BrowserRouter` for instance), you need to set the `<Admin basename>` prop, so that react-admin routes include the basename in all links (e.g. `/admin/posts/123/show`).
886
+
However, if you serve your admin from a sub path AND use another Router (like [`<BrowserRouter>`](https://reactrouter.com/en/main/router-components/browser-router) for instance), you need to set the `<Admin basename>` prop, so that react-admin routes include the basename in all links (e.g. `/admin/posts/123/show`).
858
887
859
888
```tsx
860
889
import { Admin, Resource } from'react-admin';
890
+
import { BrowserRouter } from'react-router-dom';
861
891
862
892
const App = () => (
863
893
<BrowserRouter>
@@ -870,7 +900,7 @@ const App = () => (
870
900
871
901
This makes all links be prefixed with `/admin`.
872
902
873
-
Note that it is your responsibility to serve the admin from the sub path, e.g. by setting the `homepage` field in your`package.json` if you use [Create React App](https://create-react-app.dev/docs/deployment/#building-for-relative-paths).
903
+
Note that it is your responsibility to serve the admin from the sub path, e.g. by setting the `base` field in `vite.config.ts` if you use [Vite.js](https://vitejs.dev/config/shared-options.html#base), or the `homepage` field in`package.json` if you use [Create React App](https://create-react-app.dev/docs/deployment/#building-for-relative-paths).
874
904
875
905
If you want to use react-admin as a sub path of a larger React application, check the next section for instructions.
0 commit comments