The page did not jump after isAuth modification?

modified isAuth to true, after clicking login on the login page, but the page did not jump to dashboard?

Auth.js

import React, { Component } from "react"
import { Redirect } from "react-router-dom"
import { connect } from "react-redux"

import { login } from "./Auth.redux"

// @connect(
//     state => state
// )
class Auth extends Component{
    handleClickLogin(){
        this.props.login()
    }
    render(){
        //console.log(this.props)
        return(
            <div>
                {this.props.isAuth ? <Redirect to="/dashboard" /> : null}
                

,

<button onClick={() => this.handleClickLogin()}></button> </div> ) } } const mapStateToProps = state => { return { auth: state.auth } } const authCreators = {login} export default connect(mapStateToProps, authCreators)(Auth)

Auth.redux.js

const LOGIN = "login"
const LOGOUT = "logout"

const initialState = {
    isAuth: false,
    username: "ok"
}

export function auth(state=initialState, action){
    switch(action.type){
        case LOGIN:
            return {...state, isAuth: true}
        case LOGOUT:
            return {...state, isAuth: false}
        default:
            return state
    } 
}

export function login(){
    return {type: LOGIN}
}

export function logout(){
    return {type: LOGOUT}
}

Apr.07,2021

there was an error in Auth.js and Dashboard.js getting isAuth from store. Because isAuth is placed in the object auth, it should be isAuth: state.auth.isAuth when getting it

Menu