@modern-js/main-doc 0.0.0-nightly-20250521160333 → 0.0.0-nightly-20250525160318
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -88,73 +88,3 @@ export default () => {
|
|
|
88
88
|
`<Outlet>` is a new API in React Router 6. For details, see [Outlet](https://reactrouter.com/en/main/components/outlet#outlet).
|
|
89
89
|
|
|
90
90
|
:::
|
|
91
|
-
|
|
92
|
-
## Upgrading to React Router v7
|
|
93
|
-
|
|
94
|
-
React Router v7 reduces bundle size (approximately 15% smaller) compared to React Router v6, provides a more efficient route matching algorithm, and offers better support for React 19 and TypeScript. There are very few breaking changes compared to React Router v6, and Modern.js has made both versions compatible, allowing for a seamless upgrade by simply installing and registering the appropriate plugin.
|
|
95
|
-
|
|
96
|
-
:::info
|
|
97
|
-
|
|
98
|
-
For more changes from React Router v6 to React Router v7, check the [documentation](https://reactrouter.com/upgrading/v6#upgrade-to-v7)
|
|
99
|
-
|
|
100
|
-
:::
|
|
101
|
-
|
|
102
|
-
### Requirements
|
|
103
|
-
|
|
104
|
-
React Router v7 has certain environment requirements:
|
|
105
|
-
|
|
106
|
-
- Node.js 20+
|
|
107
|
-
- React 18+
|
|
108
|
-
- React DOM 18+
|
|
109
|
-
|
|
110
|
-
### Install the Plugin
|
|
111
|
-
|
|
112
|
-
First, install the Modern.js React Router v7 plugin:
|
|
113
|
-
|
|
114
|
-
```bash
|
|
115
|
-
pnpm add @modern-js/plugin-router-v7
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Configure the Plugin
|
|
119
|
-
|
|
120
|
-
Register the plugin in `modern.config.ts`:
|
|
121
|
-
|
|
122
|
-
```ts title="modern.config.ts"
|
|
123
|
-
import { routerPlugin } from '@modern-js/plugin-router-v7';
|
|
124
|
-
|
|
125
|
-
export default {
|
|
126
|
-
runtime: {
|
|
127
|
-
router: true,
|
|
128
|
-
},
|
|
129
|
-
plugins: [routerPlugin()],
|
|
130
|
-
};
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### Code Changes
|
|
134
|
-
|
|
135
|
-
In React Router v7, you no longer need to use the `defer` API; you can directly return data in the data loader:
|
|
136
|
-
|
|
137
|
-
```ts title="routes/page.data.ts"
|
|
138
|
-
import { defer } from '@modern-js/runtime/router';
|
|
139
|
-
|
|
140
|
-
export const loader = async ({ params }) => {
|
|
141
|
-
// Recommended v7 style
|
|
142
|
-
const user = fetchUser(params.id)
|
|
143
|
-
return { user };
|
|
144
|
-
|
|
145
|
-
// v6 style, still compatible with Modern.js
|
|
146
|
-
return defer({ data: 'hello' });
|
|
147
|
-
};
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
React Router v7 has also deprecated the `json` API:
|
|
151
|
-
|
|
152
|
-
```ts title="routes/page.data.ts"
|
|
153
|
-
export const loader = async ({ params }) => {
|
|
154
|
-
// Recommended v7 style
|
|
155
|
-
return { data: 'hello' };
|
|
156
|
-
|
|
157
|
-
// v6 style, still compatible with Modern.js
|
|
158
|
-
return json({ data: 'hello' });
|
|
159
|
-
};
|
|
160
|
-
```
|
|
@@ -490,6 +490,76 @@ import Motivation from '@site-docs-en/components/convention-routing-motivation';
|
|
|
490
490
|
|
|
491
491
|
<Motivation />
|
|
492
492
|
|
|
493
|
+
## Upgrading to React Router v7
|
|
494
|
+
|
|
495
|
+
React Router v7 reduces bundle size (approximately 15% smaller) compared to React Router v6, provides a more efficient route matching algorithm, and offers better support for React 19 and TypeScript. There are very few breaking changes compared to React Router v6, and Modern.js has made both versions compatible, allowing for a seamless upgrade by simply installing and registering the appropriate plugin.
|
|
496
|
+
|
|
497
|
+
:::info
|
|
498
|
+
|
|
499
|
+
For more changes from React Router v6 to React Router v7, check the [documentation](https://reactrouter.com/upgrading/v6#upgrade-to-v7)
|
|
500
|
+
|
|
501
|
+
:::
|
|
502
|
+
|
|
503
|
+
### Requirements
|
|
504
|
+
|
|
505
|
+
React Router v7 has certain environment requirements:
|
|
506
|
+
|
|
507
|
+
- Node.js 20+
|
|
508
|
+
- React 18+
|
|
509
|
+
- React DOM 18+
|
|
510
|
+
|
|
511
|
+
### Install the Plugin
|
|
512
|
+
|
|
513
|
+
First, install the Modern.js React Router v7 plugin:
|
|
514
|
+
|
|
515
|
+
```bash
|
|
516
|
+
pnpm add @modern-js/plugin-router-v7
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### Configure the Plugin
|
|
520
|
+
|
|
521
|
+
Register the plugin in `modern.config.ts`:
|
|
522
|
+
|
|
523
|
+
```ts title="modern.config.ts"
|
|
524
|
+
import { routerPlugin } from '@modern-js/plugin-router-v7';
|
|
525
|
+
|
|
526
|
+
export default {
|
|
527
|
+
runtime: {
|
|
528
|
+
router: true,
|
|
529
|
+
},
|
|
530
|
+
plugins: [routerPlugin()],
|
|
531
|
+
};
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
### Code Changes
|
|
535
|
+
|
|
536
|
+
In React Router v7, you no longer need to use the `defer` API; you can directly return data in the data loader:
|
|
537
|
+
|
|
538
|
+
```ts title="routes/page.data.ts"
|
|
539
|
+
import { defer } from '@modern-js/runtime/router';
|
|
540
|
+
|
|
541
|
+
export const loader = async ({ params }) => {
|
|
542
|
+
// Recommended v7 style
|
|
543
|
+
const user = fetchUser(params.id)
|
|
544
|
+
return { user };
|
|
545
|
+
|
|
546
|
+
// v6 style, still compatible with Modern.js
|
|
547
|
+
return defer({ data: 'hello' });
|
|
548
|
+
};
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
React Router v7 has also deprecated the `json` API:
|
|
552
|
+
|
|
553
|
+
```ts title="routes/page.data.ts"
|
|
554
|
+
export const loader = async ({ params }) => {
|
|
555
|
+
// Recommended v7 style
|
|
556
|
+
return { data: 'hello' };
|
|
557
|
+
|
|
558
|
+
// v6 style, still compatible with Modern.js
|
|
559
|
+
return json({ data: 'hello' });
|
|
560
|
+
};
|
|
561
|
+
```
|
|
562
|
+
|
|
493
563
|
## FAQ
|
|
494
564
|
|
|
495
565
|
1. Why there is `@modern-js/runtime/router` to re-export React Router API
|
|
@@ -535,3 +605,5 @@ export const init = () => {
|
|
|
535
605
|
// initialization logic
|
|
536
606
|
};
|
|
537
607
|
```
|
|
608
|
+
|
|
609
|
+
|
package/package.json
CHANGED
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "0.0.0-nightly-
|
|
18
|
+
"version": "0.0.0-nightly-20250525160318",
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"mermaid": "^11.4.1",
|
|
25
|
-
"@modern-js/sandpack-react": "0.0.0-nightly-
|
|
25
|
+
"@modern-js/sandpack-react": "0.0.0-nightly-20250525160318"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@rsbuild/plugin-sass": "1.3.1",
|