import React from "react" import {connect} from "react-redux" import {login} from "./Auth.redux" import {Redirect} from "react-router-dom" import {axios} from 'axios' @connect( state=>state.auth, {login} ) class Auth extends React.Component{ componentDidMount() { axios.get('/data') .then(res=>{ console.log(res) }) } render(){ return ( <div> {this.props.isAuth ? <Redirect to='/dashboard'></Redirect> : null} <h2>你上未登入,須登入才能看</h2> <button onClick={this.props.login}>登入</button> </div> ) } } export default Auth
"proxy": "http://localhost:9093"
不知哪錯了,總覺得好像沒到9093端口~~
全网唯一的React 16+Redux+React Router4实战课程,学到手是你的真本领!
了解课程