A
A
Artem Nanavov2020-04-16 13:02:38
React
Artem Nanavov, 2020-04-16 13:02:38

Route not working with history?

Hello everyone, I ran into 1 problem, the login component makes a post request when clicked, after which I redirect to the page with url /, (at the same time I show and hide the loader ), after which the route does not work for me, i.e. the url changes according to components for some reason the

code of the login component is not rendered

const App__singIn = props => {
    const [ name, setName ] = useState( '' )
    const [ pass, setPass ] = useState( '' )
    const [ error, setError ] = useState( false )
    const [ checked, setChecked ] = useState( false )

    const click = () => {
        props.etLoader( true )

        const url = process.env.REACT_APP_API_AUTH
        const data = {
            email: name,
            password: pass,
        }

        axios.post( url, data ).then( data =>
            data.status >= 199 && data.status <= 301 ?
                (
                    props.setLoader( false ),

                    checked ? (
                            setCookie( 'token', data.data.token, { expires: 365 }  ),
                            setCookie( 'id', data.data.id, { expires: 365 } ),
                            setCookie( 'username', data.data.username, { expires: 365 } )
                        ) : (
                            setCookie( 'token', data.data.token ),
                            setCookie( 'id', data.data.id ),
                            setCookie( 'username', data.data.username )
                    ),

                    props.setUser( true ),

                    props.browserHistory.push( '/' )
                ) : (
                    props.setLoader( false ), setError( true )
                )
        )

    }

    if ( props.loader === true ) {
        return <p> Loader </p>
    } else {
        return (
            <div >
                <div className={ s.fields }>
                    <App__input type='text' value={ name } set={ setName } text='Почта'/>

                    <App__input type='password' value={ pass } set={ setPass } text='Пароль'/>
                </div>

                <div className={ s.checked } >
                    <App__checkbox checked={ checked } setChecked={ setChecked } text='Запомнить меня' />
                </div>

                <App__btn click={ click } disable={ !name || !pass ? true : false } text='Войти'/>

                <div className={ s.changePass } >
                    Забыл пароль
                </div>
            </div>
        )
    }

}

export default App__singIn


if you don't do dom manipulation then everything works fine, but I need dom manipulation to show user icon

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question