我正在使用react-navigation v3在我的react-native应用程序中进行导航。当我启动应用程序时,它将导航至最终导航页面,即电子学
AppNavigator.js
while true; do
sleep 10;
montage -mode concatenate -tile 1x $(ls | sort -R | tail -n 5 | paste -sd " " -) montage.jpg && display montage.jpg;
done
Home.js
import { createStackNavigator, createAppContainer } from 'react-navigation';
import Home from '../container/Home';
import BooksScreen from '../container/BooksScreen'
import ElectronicsScreen from '../container/ElectronicsScreen';
const AppNavigator = createStackNavigator({
Home:Home,
Book: BooksScreen,
Electronics: ElectronicsScreen
});
export default AppContainer = createAppContainer(AppNavigator);
App.js
import React, { Component } from 'react';
import { View, Text, TouchableOpacity as Button } from 'react-native';
export default class Home extends Component {
render() {
return (
<View>
<Text> Home Page </Text>
<Button
title="Books"
onPress={this.props.navigation.navigate('Book')}
>
</Button>
<Button
title="Books"
onPress={this.props.navigation.navigate('Electronics')}
>
</Button>
</View>
);
}
}
运行代码时,它直接运行到ElectronisScreen.js。我怎样才能让它留在家里?
答案 0 :(得分:2)
将您的AppNavigator
更改为下方。
const AppNavigator = createStackNavigator({
Home: Home,
Book: BooksScreen,
Electronics: ElectronicsScreen
},
{
initialRouteName: 'Home',
});
您必须定义您的initialRouteName
。