设置一个简单的登录后,我尝试使用链接到另一个组件onPress={() => history.push('/Page')}
但在日志中显示:
找不到变量:历史
问题是:使用 NativeRouter 和 Router 仅当组件只有路由器和链接时才有效。但如果组件有任何其他东西链接文本输入、文本等,则输入和文本会继续显示。
在下面的示例中,单击链接后,即使使用 switch 和 exact,登录组件和注册组件也会显示在同一屏幕上。
所以唯一的方法似乎是使用历史。但添加后显示这个
找不到变量:历史
有人可以在此反应路由器问题上提供提示吗?
谢谢
import React, { Component } from 'react';
import { Text, TextInput, View, StyleSheet } from 'react-native';
import { Card, Button, CardSection, Input} from '../components';
import { NativeRouter, Router, Link } from 'react-router-native'
import Home from './Home';
import Signup from './Signup';
class Login extends Component {
render() {
return (
<NativeRouter>
<Card>
<Text> Login </Text>
<Input placeholder = "Email" />
<Input secureTextEntry = { true } placeholder = "Password"/>
<Button onPress={xxx}>
Log in
</Button>
<Link to='/Signup'><Text>create account</text></Link>
<Router exact path="/Signup" component={Signup} />
</Card>
</NativeRouter>
);
}
}
export default Login;