我有3个JS文件,2页(
HomePage
和
SecondPage
(1)
ComponentBlock
这增加了
主页
)
我怎样才能从
构件块
到
第二页
?
我的意思是,当我直接在主页上使用onpress按钮时,一切正常,我可以从主页导航到第二个,第二个导航到主页,但我不能从主页中添加的组件块导航到第二个。
主页:
import {createStackNavigator} from 'react-navigation';
import Second from './8-SecondPage'
import ComponentBlock from './8-Component-Block';
class Home extends React.Component {
render() {
return (
<ComponentBlock />
);
}
}
const App = createStackNavigator(
{
Home: {screen: Home},
Second: {screen: Second},
Third: {screen: ComponentBlock},
},
);
export default App;
SecondPage:
export default class Second extends Component {
render() {
return (
<View>
<TouchableOpacity
onPress={() => this.props.navigation.navigate('Home')}
>
<Text>Go to Home Page</Text>
</TouchableOpacity>
</View>
);
}
}
ComponentBlock:
export default class ComponentBlock extends Component {
render() {
return (
<View>
<Text>ComponentBlock</Text>
<TouchableOpacity
onPress={() => this.props.navigation.navigate('Second')}
>
<Text>Go to Second Page</Text>
</TouchableOpacity>
</View>
);
}
}