-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way to change route from a reflux / redux store? #112
Comments
You can use resetToRoute for this
|
hey @shakdoesgithub the way I achieve this is that I recreate the router state in redux. On every event emitted from the router, i send an action to the redux store. For every component I have, I created a Higher Order Component that has a "componentWillReceiveProps" and when the state updates, i look at the router state and perform a "toRoute" call. This allows me to dispatch router actions from any other action and the route will change. |
@ericraio That's a good approach. Additionally, I think we could modify class onForward(nextRoute, navigator) {
navigator.push(
Object.assign(nextRoute, { index: this.state.route.index + 1 || 1 })
);
} We may define a certain function like: toRoute(nextRoute){
....
} Is that better? |
@anhldbk yeah thats a good idea, that would eliminate the dependency on using the prop and the need I had for using this mixin |
@ericraio , @shakdoesgithub I've read the code in class // line #279
this.toRoute = goForward;
this.toBack = goBackwards;
this.replaceRoute = replaceRoute;
this.resetToRoute = resetToRoute;
this.reset = goToFirstRoute; So it's really straightforward to get redux works with this component. |
@anhldbk when I was looking into this, I was running into issues where I couldn't call a method on the router to change the route and components that the router renders were able to access the props. with my high order component, I was able to dry up the code with the mapStateToProps and create a common componentWillReceiveProps to handle the route transitions, not the cleanest implementation but I haven't had to change the code for months. |
@ericraio How come? Here is my code: The app import React, { StyleSheet, View, Text } from 'react-native';
import Router from 'react-native-simple-router';
import LaunchPage from './pages/LaunchPage';
const firstRoute = {
name: 'Home World',
component: LaunchPage,
statusBarProps: {
animated: true,
backgroundColor: 'red',
},
data: {
message: 'Hello World from Vietnam'
}
};
const styles = StyleSheet.create({
header: {
backgroundColor: '#5cafec',
height: 56
},
});
const statusBarProps = {
backgroundColor: '#1b6298',
};
export default class TwitterApp extends React.Component {
render() {
return (
<Router
firstRoute={firstRoute}
headerStyle={styles.header}
statusBarProps={statusBarProps}
handleBackAndroid
ref = {(router) => {
router.toRoute({ // here toRoute works as expected
name: 'Home World',
component: LaunchPage,
statusBarProps: {
animated: true,
backgroundColor: 'red',
},
data: {
message: 'Hey Eric, dont you see?'
}
});
}}
/>
);
}
} LaunchPage which is responsible for displaying a message stored in // LaunchPage.js
import React, { StyleSheet, View, Text } from 'react-native';
class LaunchPage extends React.Component {
constructor(props) {
super(props);
this.styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f5f8fa',
},
});
}
render() {
return (
<View style={this.styles.container}>
<Text>{this.props.data.message}</Text>
</View>
);
}
}
export default LaunchPage; |
I have a component that will trigger sign out action on my redux store, from the store I want to change the route to a Sign In component. Is this possible?
The text was updated successfully, but these errors were encountered: