user9157191
user9157191

Reputation:

react router Can't find variable: history

after setup a simple login i've tried to link to another component using the onPress={() => history.push('/Page')}

but in the logs show:

Can't find variable: history

The thing is: using the NativeRouter and Router works just if the component has just the routers and the links. but if the component has any nother thing link textinput, text and etc the inputs and texts keep showing.

the exemple below, after click on the link the login component and the signup component show on the same screen even using switch and exact.

so the only way seems to use the history. but after added show this

Can't find variable: history

someone can spare a hint on this react router issue?

thank's

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;

Upvotes: 0

Views: 1351

Answers (1)

pyotruk
pyotruk

Reputation: 91

Duplicates How to push to History in React Router v4?

Briefly, you have 3 options to make history.push():

Upvotes: 1

Related Questions