Skip to content

Commit 18e24a7

Browse files
authored
docs(start): add project structure to next.js migration guide (#4280)
1 parent dc1d7b9 commit 18e24a7

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

docs/start/framework/react/migrate-from-next-js.md

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,44 @@ This guide provides a step-by-step process to migrate a project from the Next.js
1010

1111
## Step-by-Step (Basics)
1212

13-
This step-by-step guide should give you an overview of how to migrate your Next.js App Router project to TanStack Start by migrating a starter template. The goal is to help you understand the basic steps involved in the migration process, so you can adapt them to your specific project needs.
13+
This step-by-step guide provides an overview of how to migrate your Next.js App Router project to TanStack Start using a starter template. The goal is to help you understand the basic steps involved in the migration process so you can adapt them to your specific project needs.
1414

1515
### Prerequisites
1616

17-
Let's start off by cloning the following [starter template](https://github.com/nrjdalal/awesome-templates/tree/main/next.js-apps/next.js-start) to follow along with this guide:
17+
Before we begin, this guide assumes your project structure looks like this:
18+
19+
```txt
20+
.
21+
├── next.config.ts
22+
├── package.json
23+
├── postcss.config.mjs
24+
├── public
25+
│ ├── file.svg
26+
│ ├── globe.svg
27+
│ ├── next.svg
28+
│ ├── vercel.svg
29+
│ └── window.svg
30+
├── README.md
31+
├── src
32+
│ └── app
33+
│ ├── favicon.ico
34+
│ ├── globals.css
35+
│ ├── layout.tsx
36+
│ └── page.tsx
37+
└── tsconfig.json
38+
```
39+
40+
Alternatively, you can follow along by cloning the following [starter template](https://github.com/nrjdalal/awesome-templates/tree/main/next.js-apps/next.js-start):
1841

1942
```sh
2043
npx gitpick nrjdalal/awesome-templates/tree/main/next.js-apps/next.js-start next.js-start-er
2144
```
2245

23-
This starter is a basic Next.js application using the App Router, which we will migrate to TanStack Start.
46+
This structure or starter is a basic Next.js application using the App Router, which we will migrate to TanStack Start.
2447

2548
### 1. Remove Next.js
2649

27-
First, uninstall Next.js and remove adjacent configuration files:
50+
First, uninstall Next.js and remove related configuration files:
2851

2952
```sh
3053
npm uninstall @tailwindcss/postcss next
@@ -42,15 +65,15 @@ TanStack Start leverages [Vite](https://vite.dev) and TanStack Router:
4265
npm i @tanstack/react-router@alpha @tanstack/react-start@alpha vite
4366
```
4467

45-
For TypeScript support and Tailwind CSS:
68+
For Tailwind CSS and resolving imports using path aliases:
4669

4770
```sh
4871
npm i -D @tailwindcss/vite tailwindcss vite-tsconfig-paths
4972
```
5073

5174
### 3. Update Project Configuration
5275

53-
Now that you've installed the necessary dependencies, you need to update your project configuration files to work with TanStack Start.
76+
Now that you've installed the necessary dependencies, update your project configuration files to work with TanStack Start.
5477

5578
- `package.json`
5679

@@ -92,13 +115,13 @@ export default defineConfig({
92115
})
93116
```
94117

95-
By default, `routesDirectory` is set to `src/routes`. If you want to maintain consistency with Next.js App Router conventions, you can set it to `src/app` instead.
118+
By default, `routesDirectory` is set to `src/routes`. To maintain consistency with Next.js App Router conventions, you can set it to `src/app` instead.
96119

97120
### 4. Adapt the Root Layout
98121

99-
> TanStack Start uses routing adjacent to Remix, with some changes to make it compatible with nested structures and support special features using tokens. Learn more about it at [Routing Concepts](/router/latest/docs/framework/react/routing/routing-concepts) guide.
122+
> TanStack Start uses a routing approach similar to Remix, with some changes to support nested structures and special features using tokens. Learn more about it at [Routing Concepts](/router/latest/docs/framework/react/routing/routing-concepts) guide.
100123
101-
Instead of `layout.tsx`, you will create a file named `__root.tsx` in the `src/app` directory. This file will serve as the root layout for your application.
124+
Instead of `layout.tsx`, create a file named `__root.tsx` in the `src/app` directory. This file will serve as the root layout for your application.
102125

103126
- `src/app/layout.tsx` to `src/app/__root.tsx`
104127

@@ -158,7 +181,7 @@ function RootLayout() {
158181

159182
### 5. Adapt the Home Page
160183

161-
Instead of `page.tsx`, you will create an `index.tsx` file for the `/` route.
184+
Instead of `page.tsx`, create an `index.tsx` file for the `/` route.
162185

163186
- `src/app/page.tsx` to `src/app/index.tsx`
164187

@@ -193,7 +216,7 @@ Instead of `page.tsx`, you will create an `index.tsx` file for the `/` route.
193216
194217
### 6. Are we migrated yet?
195218
196-
One last thing before we can run the development server, we need to create a router file that will dictate the behavior of TanStack Router used within TanStack Start.
219+
Before you can run the development server, you need to create a router file that will define the behavior of TanStack Router within TanStack Start.
197220
198221
- `src/router.tsx`
199222
@@ -219,7 +242,7 @@ declare module '@tanstack/react-router' {
219242
220243
> 🧠 Here you can configure everything from the default [preloading functionality](/router/latest/docs/framework/react/guide/preloading) to [caching staleness](/router/latest/docs/framework/react/guide/data-loading).
221244
222-
Don't worry if you see some TypeScript errors at this point. The next step will fix that.
245+
Don't worry if you see some TypeScript errors at this point; the next step will resolve them.
223246
224247
### 7. Verify the Migration
225248
@@ -229,9 +252,9 @@ Run the development server:
229252
npm run dev
230253
```
231254
232-
Then visit `http://localhost:3000`. You should see the TanStack Start welcome page with its logo and documentation link.
255+
Then, visit `http://localhost:3000`. You should see the TanStack Start welcome page with its logo and a documentation link.
233256

234-
> If you encounter issues, review the steps above and ensure file names and paths match exactly. For reference implementation, see the [after migration repository](https://github.com/nrjdalal/next-to-start).
257+
> If you encounter issues, review the steps above and ensure that file names and paths match exactly. For a reference implementation, see the [post-migration repository](https://github.com/nrjdalal/next-to-start).
235258

236259
## Next Steps (Advanced)
237260

@@ -252,7 +275,7 @@ Learn more about the [Routing Concepts](/router/latest/docs/framework/react/rout
252275

253276
### Dynamic and Catch-All Routes
254277

255-
Getting dynamic route parameters in TanStack Start is straightforward.
278+
Retrieving dynamic route parameters in TanStack Start is straightforward.
256279

257280
```tsx
258281
- export default async function Page({ // [!code --]
@@ -273,7 +296,7 @@ Getting dynamic route parameters in TanStack Start is straightforward.
273296

274297
> Note: If you've made a catch-all route (like `src/app/posts/$.tsx`), you can access the parameters via `const { _splat } = Route.useParams()`.
275298

276-
Similarly, you can get `searchParams` like `const { page, filter, sort } = Route.useSearch()`.
299+
Similarly, you can access `searchParams` using `const { page, filter, sort } = Route.useSearch()`.
277300

278301
Learn more about the [Dynamic and Catch-All Routes](/router/latest/docs/framework/react/routing/routing-concepts#dynamic-route-segments).
279302

@@ -334,13 +357,13 @@ Learn more about the [Server Routes](./server-routes.md).
334357
- } // [!code --]
335358
```
336359

337-
Instead of `next/font`, use Tailwind CSSs CSS-first approach. Install fonts (e.g. from [Fontsource](https://github.com/fontsource/fontsource)):
360+
Instead of `next/font`, use Tailwind CSSs CSS-first approach. Install fonts (for example, from [Fontsource](https://github.com/fontsource/fontsource)):
338361

339362
```sh
340363
npm i -D @fontsource-variable/dm-sans @fontsource-variable/jetbrains-mono
341364
```
342365

343-
Add to `src/app/globals.css`:
366+
Add the following to `src/app/globals.css`:
344367

345368
```css
346369
@import 'tailwindcss';

0 commit comments

Comments
 (0)