How Navigation from different File React Native

Derry Berni Cahyady
Aug 8, 2017 · 1 min read

I think navigation it’s important of part apps for example if you wanna change page Home to Profile you need function to move another page.

In this case i have SliderEntry.js how i can call function navigation from Home.js?

Structure File

First we need bind function in constructor() in Home.js

constructor(){
super();
this.redirect = this.redirect.bind(this);
}

to move page you need function to navigate in Home.js

redirect(){
this.props.navigation.navigate('YourPage');
}

And you need call your in return view

<SliderEntry
onPress= {this.redirect}
/>

In File SliderEntry.js add this code line to call function

const { onPress } = this.props;render () {
return (
<TouchableOpacity onPress={() => { onPress('YourPage'); }} n>
<Text> Move</Text>
</TouchableOpacity>
);
}

don’t forget to add page YourPage in stack navigator.

export const Root = StackNavigator({
YourPage:{
screen: YourPage
}
});

I hope it’s will helpful. if you wanna ask dont hesitate :).

Data Enthusiast | Web Developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade