How Navigation from different File React Native

Derry Berni Cahyady
1 min readAug 8, 2017

--

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 :).

--

--