Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Add Next.js integration tutorial #7879

Merged
merged 1 commit into from Jun 24, 2022
Merged

[Doc] Add Next.js integration tutorial #7879

merged 1 commit into from Jun 24, 2022

Conversation

fzaninotto
Copy link
Member

Based on https://marmelab.com/blog/2022/02/02/bootstrap-your-react-admin-project-with-nextjs.html

I could also add the authentication part, but it's for another PR.

No direct link from the sidebar yet, I'll wait until we have more integrations to make it public.

const url = `${process.env.SUPABASE_URL}/rest/v1/${requestUrl}`;
const options = {
method: req.method,
headers: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I realized in my remix example is that you also need to forward all the original request headers and override only those needed. Otherwise, some mutations do not work

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which ones? In my tests, editions and deletions work fine.

Note: I did manually copy the prefer header to allow getOne to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't remember right now but I ended up merging all the original headers and overriding the authentication ones

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll fix the example when and if needed

@djhi djhi added this to the 4.2.1 milestone Jun 24, 2022
@djhi djhi merged commit fb261b8 into master Jun 24, 2022
@djhi djhi deleted the doc-nextjs branch June 24, 2022 13:26
Comment on lines +78 to +98
## Rendering React-Admin In A Sub Route

In many cases, the admin is only a part of the application. For instance, you may want to render the admin in a subpath, e.g. `/admin`.

Next.js makes it trivial: create a `pages/admin.tsx` file with the same content as in the previous section:

```jsx
// in pages/admin.tsx
import type { NextPage } from "next";
import dynamic from "next/dynamic";

const App = dynamic(() => import("../src/admin/App"), { ssr: false });

const Admin: NextPage = () => {
return <App />;
};

export default Admin;
```

Now the admin renders at `http://localhost:3000/admin`, and you can use the Next.js routing system to add more pages.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to add a basename prop to your Admin in this case? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because react-admin uses a HashRouter and Nextjs uses another router.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants