我可以在项目中成功实现堆栈和标签导航。
import React from "react";
import { StackNavigator } from "react-navigation";
import { TabNavFooter } from "./TabNavFooter";
import { SIGNIN_KEY, SIGNUP_KEY } from "../config/routeKeys";
import {
SignupScreen,
SigninScreen,
MainFeedScreen,
ProfilePageScreen,
CommentScreen
} from "../screens";
export const Routes = StackNavigator({
signin: { screen: SigninScreen },
comments: { screen: CommentScreen },
mainfeed: { screen: TabNavFooter },
signup: { screen: SignupScreen },
profilePage: { screen: ProfilePageScreen }
});
现在我想点击评论按钮时导航。我的路由在router / index.js文件中。当我在另一个组件上时,如何使用它来导航?我试过这个,但它没有用。
export default class Post extends Component {
constructor(props) {
super(props);
}
commentPressedHandler = () => {
this.props.navigation('comments');
};
答案 0 :(得分:1)
您应该像navigate
this.props.navigation.navigate('Your Screen')
因此请尝试更改您的代码:
commentPressedHandler = () => {
this.props.navigation.navigate('comments');
};
而不是:
commentPressedHandler = () => {
this.props.navigation('comments');
};