2017-05-31 72 views
0

我正在使用React路由器的React本機應用程序。不知道我在這裏丟失了什麼,但是我安裝了react-router-native並且需要歷史記錄包,並且設置了一些將新路線推入堆棧的方法,但沒有任何反應。我console.log('點擊');檢查它是否正在發射,並且不知道什麼是錯誤的。導航在React路由器v4本機不改變場景

import React, { Component } from 'react'; 
import { View } from 'react-native'; 
import Splash from './Splash'; 
import createHistory from 'history/createMemoryHistory'; 

const history = createHistory(); 

class SplashContainer extends Component { 
    goToLogin =() => { 
    history.push('/Login'); 
    } 
    goToRegister =() => { 
    history.push('/SignUp'); 
    } 
    render() { 
    console.log(history) 
    return (
     <Splash 
     goToLogin={this.goToLogin} 
     goToRegister={this.goToRegister} 
     /> 
    ); 
    } 
} 

export default SplashContainer; 

import React from 'react'; 
import { StyleSheet, View, Text } from 'react-native'; 
import { Button } from 'native-base'; 
import { Link } from 'react-router-native'; 
import PropTypes from 'prop-types'; 

const Splash = (props) => { 
    console.log(props) 
    return (
    <View style={styles.container}> 
     <Button light block onPress={props.goToLogin}> 
     <Text>Login</Text> 
     </Button> 
     <Button dark block bordered style={{marginTop: 10}} onPress={props.goToRegister}> 
     <Text>Register</Text> 
     </Button> 
    </View> 
); 
} 

Splash.propTypes = { 
    goToLogin: PropTypes.func.isRequired, 
    goToRegister: PropTypes.func.isRequired 
} 

export default Splash; 

回答

0

我不知道你的路由器的配置,但你的方法應該是:

goToLogin =() => { 
    const { history } = this.props 
    history.push('/Login'); 
} 

history將通過路由器的堆內構件的道具傳下來的。

相關問題