关联
Link
组件呈现一个可以在按下时导航到屏幕的组件。在 Web 上使用时会呈现 <a>
标签,在其他平台上使用 Text
组件。它保留了浏览器中锚标记的默认行为,例如 Right click -> Open link in new tab"
、Ctrl+Click
/⌘+Click
等,以提供原生体验。
¥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.
href
中 <a>
标签的路径是根据你的 linking
选项 生成的。
¥The path in the href
for the <a>
tag is generated based on your linking
options.
示例:
¥Example:
import { Link } from '@react-navigation/native';
// ...
function Home() {
return (
<Link to={{ screen: 'Profile', params: { id: 'jane' }}}>
Go to Jane's profile
</Link>
);
}
如果你想使用自己的自定义触摸,可以使用 useLinkProps
代替。
¥If you want to use your own custom touchable, you can use useLinkProps
instead.
Link
组件接受 与 useLinkProps
相同的属性
¥The Link
component accepts the same props as useLinkProps