我正在尝试为使用 React Navigation 5 的 React Native 应用程序使用深度链接,并且一直在关注:https://reactnavigation.org/docs/configuring-links
这是我的代码:
...
const App = observer(() => {
const { NavTheme, themeLoaded } = useTheme();
const linking = {
prefixes: ['myurlhere://'],
config: {
screens: {
Confirmed: {
path: 'confirm'
}
}
}
};
return (
<NavigationContainer linking={linking} theme={NavTheme}>
<LoginStack.Navigator>
<LoginStack.Screen name="Login" component={Login} options={{ headerShown: false }}/>
<LoginStack.Screen name="Confirmed" component={Confirmed} options={{ headerShown: false }}/>
</LoginStack.Navigator>
</NavigationContainer>
);
});
当我转到 safari 并输入 myurlhere://confirm 时,它会打开应用程序,然后显示以下错误:
console.error: "The action 'NAVIGATE' with payload {"name":"confirm","params":{}} was not handled by any navigator.
Do you have a screen named 'confirm'?
If you're trying to navigate to a screen in a nested navigator, see https://reactnavigation.org/docs/nesting-navigators#navigating-to-a-screen-in-a-nested-navigator.
我希望它能导航到我的已确认路线。我做错了什么?
最佳答案
我假设你使用的是旧版本的 react-navigation
尝试像这样更改您的配置对象
const linking = {
prefixes: ['myurlhere://'],
config: {
Confirmed: 'confirm'
}
};
关于reactjs - React Navigation 5 - 深度链接不接受给定路径并按预期解析为状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62674058/