Skip to content

Commit 52f912b

Browse files
committed
added explanations about subpath routing no matter the router system
1 parent 364f10b commit 52f912b

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

docs/NextJs.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,15 @@ The file you import the Admin app into Next.js depends on the router system you
9393
// depending of the Router you choose:
9494
// - in src/app/page.tsx for App Router system
9595
// - or in src/pages/index.tsx for Pages Router system
96+
import { NextPage } from "next";
9697
import dynamic from "next/dynamic";
9798
const AdminApp = dynamic(() => import("@/components/AdminApp"), { ssr: false });
9899

99-
export default function Home() {
100+
const Home: NextPage = () => {
100101
return <AdminApp />;
101-
}
102+
};
103+
104+
export default Home;
102105
```
103106

104107
Now, start the server with `yarn dev`, browse to `http://localhost:3000/`, and you should see the working admin:
@@ -107,19 +110,22 @@ Now, start the server with `yarn dev`, browse to `http://localhost:3000/`, and y
107110

108111
Starting from there, you can [Add an API](#adding-an-api) as described in the next section, and/or add features to the Next.js app, as explained in the [Getting started tutorial](./Tutorial.md)
109112

110-
## Specific Use Cases For Pages Router
111-
112-
### Rendering React-Admin In A Sub Route
113+
## Rendering React-Admin In A Sub Route
113114

114115
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`.
115116

116-
Next.js makes it trivial: create a `src/pages/admin.tsx` file with the same content as in the previous section:
117+
Depending of the router system you choose, create the subpage in this following file:
118+
- you choose **App Router**: create the subpage in `src/app/admin/page.tsx`
119+
- you choose **Pages Router**: create the subpage in `src/pages/admin/index.tsx`
120+
121+
No matter which system you choose, the file should contains the following code:
117122

118123
```tsx
119-
// in src/pages/admin.tsx
120-
import type, { NextPage } from "next";
124+
// depending of the Router you choose:
125+
// - in src/app/admin/page.tsx for App Router system
126+
// - or in src/pages/admin/index.tsx for Pages Router system
127+
import { NextPage } from "next";
121128
import dynamic from "next/dynamic";
122-
123129
const AdminApp = dynamic(() => import("@/components/AdminApp"), { ssr: false });
124130

125131
const Admin: NextPage = () => {

0 commit comments

Comments
 (0)