我正在尝试在我的 React native 应用程序中应用深度链接。我按照文档进行操作,在尝试进行第一次测试时遇到了一些问题,我相信这是因为使用了堆栈导航器和抽屉菜单。
堆栈:
const SignedInStack = () => (
<Stack.Navigator>
<Stack.Screen name='Confluence' component={Confluence} />
<Stack.Screen name='QRCode' component={Main} />
<Stack.Screen name='Notifications' component={Notifications} />
</Stack.Navigator>
)
抽屉菜单:
const DrawerMenu = () => (
<Drawer.Navigator
screenOptions={{ headerShown: false }}
drawerContent={(props) => <CustomDrawerContent {...props} />}
>
<Drawer.Screen
name="SignedInStack"
component={SignedInStack}
/>
<Drawer.Navigator/>
);
应用程序.js:
const App = () => (
<NavigationContainer linking={{
prefixes: ['example://'],
config: {
screens: {
Notifications: 'notifications',
},
},
}}>
<DrawerMenu />
</NavigationContainer>
);
我在堆栈初始屏幕上的第一个 useEffect:
useEffect(() => {
Linking.openURL('example://app/notifications');
}, []);
在尝试重定向到通知屏幕后,我立即收到以下错误消息: “错误:无法打开 URL 'example://app/notifications':找不到处理 Intent { act=android.intent.action.VIEW dat=example://app/notifications flg=0x10000000 } 的 Activity ”
最佳答案
我没有使用 Linking.openURL
,而是使用了 linkTo ,如下例所示:
import { useLinkTo } from '@react-navigation/native';
...
const linkTo = useLinkTo();
useEffect(() => {
linkTo('/notifications');
}, []);
关于android - 无法打开 URL...找不到处理 Intent 的 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72772790/