如何在 React Native 中创建路由?
How to make a route in react native?
路由器不工作,我尝试了很多形式但没有工作,有人可以帮助我吗?
以下错误是:设备:(487:41) undefined is not an object (evaluating '_this2.props.navigation.navigate')
import { createDrawerNavigator, createAppContainer } from "react-navigation";
import Noturno from './containerNoturno.js';
import Linhas from './Linhas.js';
import LSaida from './LinhasSaida.js';
import Main from './containerDiurno.js';
import Ajuda from './Ajuda.js';
import Sobre from './sobre.js';
import Intro from './intro.js';
import GalopolisSantaCoronaNoturno from './Noturno/GalopolisSantaCorona.js';
const AppNavigator = createDrawerNavigator({
Menu: { screen: Main },
Noturno: { screen: Noturno },
Linhas: { screen: Linhas },
Linhas_Saida: { screen: LSaida },
Ajuda: { screen: Ajuda },
Sobre: { screen: Sobre },
Galopolis_Noturno: { screen: GalopolisSantaCoronaNoturno },
});
export default createAppContainer(AppNavigator);
这是另一个代码:
<TouchableOpacity
onPress={() => this.props.navigation.navigate('Noturno')}
style={styles.fab}>
<Image
source={require('../assets/noite.png')}
style={{ width: 50, height: 50 }}
/>
</TouchableOpacity>
请点开关注link帮帮我...
您正在访问不属于 StackNavigator
的子组件 "Noturno.js" 中的导航道具
您可以像这样访问道具(Access the navigation prop from any component)
更新文件"Noturno.js"
import { withNavigation } from 'react-navigation';
....
class App extends React.Component
....
export default withNavigation(App);
路由器不工作,我尝试了很多形式但没有工作,有人可以帮助我吗?
以下错误是:设备:(487:41) undefined is not an object (evaluating '_this2.props.navigation.navigate')
import { createDrawerNavigator, createAppContainer } from "react-navigation";
import Noturno from './containerNoturno.js';
import Linhas from './Linhas.js';
import LSaida from './LinhasSaida.js';
import Main from './containerDiurno.js';
import Ajuda from './Ajuda.js';
import Sobre from './sobre.js';
import Intro from './intro.js';
import GalopolisSantaCoronaNoturno from './Noturno/GalopolisSantaCorona.js';
const AppNavigator = createDrawerNavigator({
Menu: { screen: Main },
Noturno: { screen: Noturno },
Linhas: { screen: Linhas },
Linhas_Saida: { screen: LSaida },
Ajuda: { screen: Ajuda },
Sobre: { screen: Sobre },
Galopolis_Noturno: { screen: GalopolisSantaCoronaNoturno },
});
export default createAppContainer(AppNavigator);
这是另一个代码:
<TouchableOpacity
onPress={() => this.props.navigation.navigate('Noturno')}
style={styles.fab}>
<Image
source={require('../assets/noite.png')}
style={{ width: 50, height: 50 }}
/>
</TouchableOpacity>
请点开关注link帮帮我...
您正在访问不属于 StackNavigator
的子组件 "Noturno.js" 中的导航道具您可以像这样访问道具(Access the navigation prop from any component)
更新文件"Noturno.js"
import { withNavigation } from 'react-navigation';
....
class App extends React.Component
....
export default withNavigation(App);