导航.js
import React,{ Component} from 'react'
import { createStackNavigator,createAppContainer } from 'react-navigation'
import Login from './screens/login'
import SplashScreen from './screens/splashScreen'
// export const Nav = createStackNavigator({
// splashScreen: { screen: SplashScreen },
// loginScreen: { screen:Login },
// },{ initialRouteName: 'splashScreen' })
// export default createAppContainer(Nav);
const Nav = createStackNavigator({
loginScreen: { screen: Login },
splashScreen: {screen: SplashScreen},
{
initialRouteName: 'splashScreen',
}
})
export default createAppContainer(Nav);
闪屏.js
import React, { Component } from "react";
import { Image, StyleSheet, Text, TouchableOpacity, View } from "react-native";
import { appContainer } from '../styleSheet'
import { Nav } from '../navigations'
import { createStackNavigator,createAppContainer } from 'react-navigation'
class SplashScreen extends Component {
componentWillMount(){
setTimeout(() => {
// alert('I will redirect')
this.props.navigation.navigate("loginScreen");
}, 3000);
}
render() {
return (
<View style={appContainer.AppContainer}>
<Text style={appContainer.splashSC}> Who Around Me </Text>
</View>
)
}
}
export default SplashScreen
登录.js
import React, { Component } from "react";
import { Image, StyleSheet, Text, TouchableOpacity, View } from "react-native";
import { appContainer,buttons } from '../styleSheet'
class Login extends Component {
render() {
return (
<View style={appContainer.AppContainer}>
<Text style={buttons.loginBtnText}>
Login with Sim
</Text>
</View>
)
}
}
export default Login
应用程序.js
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
* @lint-ignore-every XPLATJSCOPYRIGHT1
*/
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import SplashScreen from './screens/splashScreen'
import { createStackNavigator,createAppContainer } from 'react-navigation'
import Login from './screens/login'
import { Nav } from './navigations'
const App = () => (
<Nav />
);
export default App;
index.android.js
import React, { Component } from "react";
import { AppRegistry } from "react-native";
import { createStackNavigator,createAppContainer } from 'react-navigation'
import App from "./src/App";
AppRegistry.registerComponent("WhoAroundMe", () => App);
this.props.navigation.navigate("loginScreen"); 抛出错误
this.props.navigation.navigate 未定义
无法通过做很多谷歌来解决。
任何帮助表示赞赏。谢谢