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/link.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: Link
4
4
sidebar_label: Link
5
5
---
6
6
7
-
The `Link` component renders a component that can navigate to a screen on press. This renders an`<a>` tag when using on the Web and It uses a `Text` component on other platforms. It preserves the default behavior of anchor tags in the browser such as `Right click -> Open link in new tab"`, `Ctrl+Click`/`⌘+Click` etc. to provide a native experience.
7
+
The `Link` component renders a component that can navigate to a screen on press. This renders a`<a>` tag when used on the Web and uses a `Text` component on other platforms. It preserves the default behavior of anchor tags in the browser such as `Right click -> Open link in new tab"`, `Ctrl+Click`/`⌘+Click` etc. to provide a native experience.
8
8
9
9
The path in the `href` for the `<a>` tag is generated based on your [`linking` options](navigation-container.md#linking).
10
10
@@ -17,13 +17,13 @@ import { Link } from '@react-navigation/native';
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/use-link-props.md
+43-49
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,9 @@ title: useLinkProps
4
4
sidebar_label: useLinkProps
5
5
---
6
6
7
-
The `useLinkProps` hook let's build our custom link components which let us navigate to a screen using a path instead of a screen name based on the [`linking` options](navigation-container.md#linking). It takes a path and returns an object with some props that you can pass to a component.
7
+
The `useLinkProps` hook lets us build our custom link component. The link component can be used as a button to navigate to a screen. On the web, it will be rendered as an anchor tag (`<a>`) with the `href` attribute so that all the accessibility features of a link are preserved, e.g. - such as `Right click -> Open link in new tab"`, `Ctrl+Click`/`⌘+Click` etc.
8
+
9
+
It returns an object with some props that you can pass to a component.
8
10
9
11
Example:
10
12
@@ -13,82 +15,54 @@ import { useLinkProps } from '@react-navigation/native';
13
15
14
16
// ...
15
17
16
-
constLinkButton= ({ to, action, children, ...rest }) => {
17
-
const{ onPress, ...props} =useLinkProps({ to, action });
The `props` object returned by `useLinkProps` contains the required props for accessible link components. When we use these props on `View`, `Text` etc., the link component responds to user actions such as `Ctrl+Click`/`⌘+Click` to open links in new tab while keeping regular clicks within the same web page.
61
-
62
-
There are couple of important things to note when using `useLinkProps` with current version of React Native for Web:
63
-
64
-
1. You must explicitly pass `onPress` as the `onClick` prop, otherwise in-page navigation won't work
65
-
2. You can only use `View` or `Text` with `useLinkProps`. The `TouchableX` components don't support a correct `onClick` event which we need
66
-
67
-
In a future version of React Native for Web, these won't be an issue and you'll be able to have the same code for links on Web, iOS and Android. But until then, you need to write platform specific code for Web and native.
68
-
69
43
## Options
70
44
71
-
### `to`
45
+
### `screen` and `params`
72
46
73
-
You can pass an object with a `screen` property:
47
+
You can pass `screen` and `params` to navigate to a screen on press:
The syntax of this object is the same as [navigating to a screen in a nested navigators](nesting-navigators.md#navigating-to-a-screen-in-a-nested-navigator). This uses a `navigate` action for navigation by default, unless you specify a different action.
88
-
89
-
Alternatively, you can also pass an absolute path to the screen, e.g. - `/profile/jane`.
59
+
If you want to navigate to a nested screen, you can pass the name of the `screen` in `params` similar to [navigating to a screen in a nested navigator](nesting-navigators.md#navigating-to-a-screen-in-a-nested-navigator):
90
60
91
-
This will be used for the `href` prop as well as for in-page navigation.
If the `action` prop is not specified, the path provided to the `to` prop will be used and dispatched as a `navigate` action.
91
+
The `screen` and `params` props can be omitted if the `action` prop is specified. In that case, we recommend specifying the `href` prop as well to ensure that the link is accessible.
92
+
93
+
### `href`
94
+
95
+
The `href` is used for the `href` attribute of the anchor tag on the Web to make the links accessible. By default, this is automatically determined based on the [`linking` options](navigation-container.md#linking) using the `screen` and `params` props.
96
+
97
+
If you want to use a custom `href`, you can pass it as the `href` prop:
0 commit comments