Skip to content

Commit 0808152

Browse files
committed
docs(router): add code snippet
1 parent ace95d0 commit 0808152

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

docs/router/framework/react/guide/automatic-code-splitting.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,33 @@ This means that it creates three separate lazy-loaded chunks for each route. Res
7878

7979
For automatic code splitting to work, there are some rules in-place to make sure that this process can reliably and predictably happen.
8080

81-
1. **Do not export route properties**: Route properties like `component`, `loader`, etc., should not be exported from the route file. Exporting these properties results in them being bundled into the main application bundle, which means that they will not be code-split.
81+
#### Do not export route properties
8282

83-
2. **That's it!** There are no other restrictions. You can use any other JavaScript or TypeScript features in your route files as you normally would. If you run into any issues, please [open an issue](https://github.com/tanstack/router/issues) on GitHub.
83+
Route properties like `component`, `loader`, etc., should not be exported from the route file. Exporting these properties results in them being bundled into the main application bundle, which means that they will not be code-split.
84+
85+
```tsx
86+
import { createRoute } from '@tanstack/react-router'
87+
88+
export const Route = createRoute('/posts')({
89+
// ...
90+
notFoundComponent: PostsNotFoundComponent,
91+
})
92+
93+
// ❌ Do NOT do this!
94+
// Exporting the notFoundComponent will prevent it from being code-split
95+
// and will be included in the main bundle.
96+
export function PostsNotFoundComponent() {
97+
//
98+
// ...
99+
}
100+
101+
function PostsNotFoundComponent() {
102+
//
103+
// ...
104+
}
105+
```
106+
107+
**That's it!** There are no other restrictions. You can use any other JavaScript or TypeScript features in your route files as you normally would. If you run into any issues, please [open an issue](https://github.com/tanstack/router/issues) on GitHub.
84108

85109
## Granular control
86110

0 commit comments

Comments
 (0)