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/server-rendering.md
+6
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,12 @@ This guide will cover how to server render your React Native app using React Nat
12
12
1. Rendering the correct layout depending on the request URL
13
13
2. Setting appropriate page metadata based on the focused screen
14
14
15
+
::: warning
16
+
17
+
Server rendering support is currently limited. It's not possible to provide a seamless SSR experience due to a lack of APIs such as media queries. In addition, many third-party libraries often don't work well with server rendering.
18
+
19
+
:::
20
+
15
21
## Pre-requisites
16
22
17
23
Before you follow the guide, make sure that your app already renders fine on server. To do that, you will need to ensure the following:
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/web-support.md
+70-14
Original file line number
Diff line number
Diff line change
@@ -4,30 +4,86 @@ title: React Navigation on the Web
4
4
sidebar_label: Web support
5
5
---
6
6
7
-
:::warning
7
+
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
8
9
-
Support for web is experimental and a work in progress. It has bugs, is missing many features and the API for web integration may change in minor versions. Please help us test it and open bug reports if you encounter a bug.
9
+
## Pre-requisites
10
10
11
-
:::
11
+
While Web support works out of the box, there are some things to configure to ensure a good experience on the web:
12
12
13
-
React Navigation's web support currently requires using [React Native for Web](https://github.com/necolas/react-native-web). This approach lets us reuse the same code on both React Native and Web.
13
+
1.[**Configure linking**](configuring-links.md)
14
14
15
-
Currently, the following features are available:
15
+
Configuring linking allows React Navigation to integrate with the browser's URL bar. This is crucial for web apps to have proper URLs for each screen.
16
16
17
-
-[URL integration in browser](configuring-links.md)
18
-
-[Accessible links](link.md)
19
-
-[Server rendering](server-rendering.md)
17
+
2.[**Use Button or Link components**](link.md)
20
18
21
-
It's important to use links as the primary way of navigation instead of navigation actions such as `navigation.navigate`. It'll ensure that your links are properly usable on web.
19
+
You may be familiar with using `navigation.navigate` to navigate between screens. But it's important to avoid using it when supporting the web. Instead, use the `Link` or [`Button`](elements.md#button) components to navigate between screens. This ensures that an anchor tag is rendered which provides the expected behavior on the web.
22
20
23
-
Some of the navigators are also configured differently on web or provide additional web specific features:
21
+
3.[**Server rendering**](server-rendering.md)
24
22
25
-
1. The [drawer](drawer-navigator.md) and [bottom tab](bottom-tab-navigator.md) navigators show hyperlinks in the drawer sidebar and tab bar respectively.
26
-
2. Swipe gestures are not available on [drawer](drawer-navigator.md) and [stack](stack-navigator.md) navigators when using on the web.
27
-
3. By default, [stack](stack-navigator.md) navigator disables page transition animations, but it can be re-enabled by specifying `animationEnabled: true`.
23
+
Currently, React Navigation works best with fully client-side rendered apps. However, minimal server-side rendering support is available. So you can optionally choose to server render your app.
28
24
29
25
:::note
30
26
31
-
Unlike React Navigation 4, you don't need to install a separate package to use web integration when using React Native for Web. If you have the `@react-navigation/web` package installed, please uninstall it because it cannot be used with React Navigation 6.
27
+
In React Navigation 4, it was necessary to install a separate package called `@react-navigation/web`to use web integration. This package is no longer needed in recent versions of React Navigation. If you have it installed, make sure to uninstall it to avoid conflicts.
32
28
33
29
:::
30
+
31
+
## Web-specific behavior
32
+
33
+
Some of the navigators have different behavior on the web compared to native platforms:
Native Stack Navigator uses the platform's primitives to handle animations and gestures on native platforms. However, animations and gestures are not supported on the web.
38
+
39
+
2.[**Stack Navigator**](stack-navigator.md)
40
+
41
+
Stack Navigator uses [`react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/) to handle swipe gestures on native platforms. However, gestures are not supported on the web.
42
+
43
+
In addition, screen transitions are disabled by default on the web. You can enable them by setting `animationEnabled: true` in the navigator's options.
44
+
45
+
3.[**Drawer Navigator**](drawer-navigator.md)
46
+
47
+
Drawer Navigator uses [`react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/) to handle swipe gestures and [`react-native-reanimated`](https://docs.swmansion.com/react-native-reanimated/) for animations on native platforms. However, gestures are not supported on the web, and animations are handled using CSS transitions.
48
+
49
+
In addition, navigators render hyperlinks on the web when possible, such as in the drawer sidebar, tab bar, stack navigator's back button, etc.
50
+
51
+
Since `react-native-gesture-handler` and `react-native-reanimated` are not used on the web, avoid importing them in your own code to reduce the bundle size unless you need them for your components. You can use `.native.js` or `.native.ts` extensions for code specific to native platforms.
52
+
53
+
## Configuring hosting providers
54
+
55
+
React Navigation is designed for Single Page Applications (SPAs). This usually means that the `index.html` file needs to be served for all routes.
56
+
57
+
During development, the bundler such as Webpack or Metro automatically handles this. However, when deploying the site, you may need to configure redirects to ensure that the `index.html` file is served for all routes to avoid 404 errors.
58
+
59
+
Here are instructions for some of the popular hosting providers:
60
+
61
+
### Netlify
62
+
63
+
To handle redirects on Netlify, add the following in the `netlify.toml` file at the root of your project:
64
+
65
+
```toml
66
+
[[redirects]]
67
+
from = "/*"
68
+
to = "/index.html"
69
+
status = 200
70
+
```
71
+
72
+
### Vercel
73
+
74
+
To handle redirects on Vercel, add the following in the `vercel.json` file at the root of your project:
GitHub pages doesn't support such redirection configuration for SPAs. There are a couple of ways to work around this:
87
+
88
+
- Rename your `index.html` to `404.html`. This will serve the `404.html` file for all routes. However, this will cause a 404 status code to be returned for all routes. So it's not ideal for SEO.
89
+
- Write a script that generates copies the `index.html` file to all routes in the build output. For example, if your app has routes `/`, `/about`, and `/contact`, you can copy the `index.html` file to `about.html` and `contact.html`.
0 commit comments