Answers for "pass params to page from router"

2

router navigate pass params

this.router.navigate(['action-selection'], { state: { example: 'bar' } });
...
constructor(private router: Router) {
  console.log(this.router.getCurrentNavigation().extras.state.example); 
  // should log out 'bar'
}
Posted by: Guest on December-08-2020
0

Passing parameters to routes

class HomeScreen extends React.Component {  render() {    return (      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>        <Text>Home Screen</Text>        <Button          title="Go to Details"          onPress={() => {            this.props.navigation.navigate('Details', {              itemId: 86,              otherParam: 'anything you want here',            });          }}        />      </View>    );  }}
class DetailsScreen extends React.Component {  render() {    const { navigation } = this.props;    return (      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>        <Text>Details Screen</Text>        <Text>          itemId: {JSON.stringify(navigation.getParam('itemId', 'NO-ID'))}        </Text>        <Text>          otherParam:          {JSON.stringify(navigation.getParam('otherParam', 'default value'))}        </Text>        <Button          title="Go to Details... again"          onPress={() =>            navigation.push('Details', {              itemId: Math.floor(Math.random() * 100),            })          }        />      </View>    );  }}
Posted by: Guest on October-10-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language