关联
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 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.
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 screen="Profile" params={{ id: 'jane' }}>
Go to Jane's profile
</Link>
);
}
如果你想使用自己的自定义链接组件,可以改用 useLinkProps。
¥If you want to use your own custom link component, you can use useLinkProps instead.
Link 组件接受 与 useLinkProps 相同的属性
¥The Link component accepts the same props as useLinkProps