You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/how-to/pre-rendering.md
+84-22Lines changed: 84 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,43 +9,105 @@ title: Pre-Rendering
9
9
<br/>
10
10
<br/>
11
11
12
-
Pre-Rendering allows you to speed up page loads for static content by rendering pages at build time instead of at runtime. Pre-rendering is enabled via the `prerender` config in `react-router.config.ts` and can be used in two ways based on the `ssr` config value:
12
+
Pre-Rendering allows you to speed up page loads for static content by rendering pages at build time instead of at runtime.
13
13
14
-
- Alongside a runtime SSR server with `ssr:true` (the default value)
15
-
- Deployed to a static file server with `ssr:false`
14
+
## Configuration
15
+
16
+
Pre-rendering is enabled via the `prerender` config in `react-router.config.ts`.
17
+
18
+
The simplest configuration is a boolean `true` which will pre-render all off the applications static paths based on `routes.ts`:
// all static paths (no dynamic segments like "/post/:slug")
31
-
prerender: true,
46
+
If you need to perform more complex and/or asynchronous logic to determine the paths, you can also provide a function that returns an array of paths. This function provides you with a `getStaticPaths` method you can use to avoid manually adding all of the static paths in your application:
<docs-warning>This API is experimental and subject to breaking changes in
65
+
minor/patch releases. Please use with caution and pay **very** close attention
66
+
to release notes for relevant changes.</docs-warning>
67
+
68
+
By default, pages are pre-rendered one path at a time. You can enable concurrency to pre-render multiple paths in parallel which can speed up build times in many cases. You should experiment with the value that provides the best performance for your app.
69
+
70
+
To specify concurrency, move your `prerender` config down into a `prerender.paths` field and you can specify the concurrency in `prerender.unstable_concurrency`:
Pre-Rendering can be used in two ways based on the `ssr` config value:
92
+
93
+
- Alongside a runtime SSR server with `ssr:true` (the default value)
94
+
- Deployed to a static file server with `ssr:false`
95
+
96
+
### Pre-rendering with `ssr:true`
97
+
98
+
When pre-rendering with `ssr:true`, you're indicating you will still have a runtime server but you are choosing to pre-render certain paths for quicker Response times.
During development, pre-rendering doesn't save the rendered results to the public directory, this only happens for `react-router build`.
91
153
92
-
## Pre-rendering with `ssr:false`
154
+
###Pre-rendering with `ssr:false`
93
155
94
156
The above examples assume you are deploying a runtime server but are pre-rendering some static pages to avoid hitting the server, resulting in faster loads.
95
157
@@ -108,7 +170,7 @@ If you specify `ssr:false` without a `prerender` config, React Router refers to
108
170
109
171
If you want to pre-render paths with `ssr:false`, those matched routes _can_ have loaders because we'll pre-render all of the matched routes for those paths, not just the root. You cannot include `actions` or `headers` functions in any routes when `ssr:false` is set because there will be no runtime server to run them on.
110
172
111
-
### Pre-rendering with a SPA Fallback
173
+
####Pre-rendering with a SPA Fallback
112
174
113
175
If you want `ssr:false` but don't want to pre-render _all_ of your routes - that's fine too! You may have some paths where you need the performance/SEO benefits of pre-rendering, but other pages where a SPA would be fine.
When pre-rendering with `ssr:false`, React Router will error at build time if you have invalid exports to help prevent some mistakes that can be easily overlooked.
0 commit comments