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}
}