Skip to main content
Version: 7.x

useRoutePath

useRoutePath 钩子可用于基于 linking 配置 获取路由的路径。如果你需要为应用中的特定路由生成 URL 以作为深层链接共享,这将很有用。

¥The useRoutePath hook can be used to get the path of a route based on the linking configuration. This can be useful if you need to generate a URL for a specific route in your app to share as a deep link.

示例

¥Example

import { useRoutePath } from '@react-navigation/native';

function MyComponent() {
const path = useRoutePath();

// Construct a URL using the path and app's base URL
const url = new URL(path, 'https://example.com');

return <Text>Shareable URL: {url.href}</Text>;
}