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: versioned_docs/version-7.x/web-support.md
+67-1Lines changed: 67 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,12 @@
1
1
---
2
2
id: web-support
3
-
title: React Navigation on the Web
3
+
title: React Navigation on Web
4
4
sidebar_label: Web support
5
5
---
6
6
7
+
import Tabs from '@theme/Tabs';
8
+
import TabItem from '@theme/TabItem';
9
+
7
10
React Navigation has built-in support for the Web platform. This allows you to use the same navigation logic in your React Native app as well as on the web. The navigators require using [React Native for Web](https://github.com/necolas/react-native-web) to work on the web.
8
11
9
12
## Pre-requisites
@@ -28,6 +31,69 @@ In React Navigation 4, it was necessary to install a separate package called `@r
28
31
29
32
:::
30
33
34
+
## Lazy loading screens
35
+
36
+
By default, screen components are bundled in the main bundle. This can lead to a large bundle size if you have many screens. It's important to keep the bundle size small on the web for faster loading times.
37
+
38
+
To reduce the bundle size, you can use [dynamic `import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) with [`React.lazy`](https://react.dev/reference/react/lazy) to lazy load screens:
Make sure to use `React.lazy`**outside** the component containing the navigator configuration. Otherwise, it will return a new component on each render, causing the [screen to be unmounted and remounted](troubleshooting.md#screens-are-unmountingremounting-during-navigation) every time the component rerenders.
87
+
88
+
:::
89
+
90
+
</TabItem>
91
+
</Tabs>
92
+
93
+
This will split the screen components into separate chunks (depending on your bundler) which are loaded on-demand when the screen is rendered. This can significantly reduce the initial bundle size.
94
+
95
+
In addition, you can use the [`screenLayout`](navigator.md#screen-layout) to wrap your screens in a [`<Suspense>`](https://react.dev/reference/react/Suspense) boundary. The suspense fallback can be used to show a loading indicator and will be shown while the screen component is being loaded.
96
+
31
97
## Web-specific behavior
32
98
33
99
Some of the navigators have different behavior on the web compared to native platforms:
0 commit comments