Wap*_*vam 3 reactjs react-native react-navigation
我只想要反应本机中当前路线或屏幕的名称,我可以在条件下使用它。我正在使用基于反应类的组件。
保留导航容器的引用,然后调用getCurrentRoute().name该引用:
class App {
navigationRef = null
render() {
<NavigationContainer ref={ref => this.navigationRef = ref}>
.....
</NavigationContainer>
}
getCurrentRouteName() {
return this.navigationRef.getCurrentRoute().name
}
}
Run Code Online (Sandbox Code Playgroud)
来源: https: //reactnavigation.org/docs/screen-tracking/(我刚刚将基于函数的组件语法转换为等效的类组件之一)
| 归档时间: |
|
| 查看次数: |
10238 次 |
| 最近记录: |