使用 UseNavigation 导航到特定屏幕

问题描述 投票:0回答:1
const navigation = useNavigation(); 
navigation.navigate('Profile')}

在 .navigate 上出现此错误

No overload matches this call.
Argument of type '[string]' is not assignable to parameter of type 'never'.
Overload 2 of 2, '(options: never): void', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'never'

我们获得 props 的导航道具工作没有任何问题,但我想在不是屏幕的组件中使用它

我的反应导航版本

"@react-navigation/native": "^6.1.8",
"@react-navigation/stack": "^6.3.18",
react-native expo react-navigation
1个回答
0
投票

这是一个正在使用的解决方案。我在导航页面名称后面添加了

as never
标签。这不是最好的解决方案,但错误消失了。

navigation.navigate('Profile' as never)}
© www.soinside.com 2019 - 2024. All rights reserved.