当前位置: 首页 > 知识库问答 >
问题:

失败的道具类型:无效的道具组件的类型'对象'提供给路由,预期的功能?

晁绍辉
2023-03-14
import React, { Component } from "react";
import { withRouter } from 'react-router';
import { NavLink } from 'react-router-dom';
import { connect } from 'react-redux';

import { logout } from '../../store/actions/auth';

class Navbar extends Component {
    render() {
        const { isAuthenticated } = this.props;


//Here I am trying to authenticate a user so once loggedIn the user can 
//manage the phlog using the phlog manager link

        const phlogManagerLink = (
            <div className='nav-link-wrapper'>
                <NavLink exact to='/phlog-manager/' activeClassName='nav-link-active'>
                    <button key='1' className='navbar-links-btn'>
                        <div className='navbar-links-btn-txt'>
                            Phlog Manager
                        </div>
                    </button>
                </NavLink>
            </div>
        );

        const logoutLink = (
            <div className='nav-link-wrapper'>
                <NavLink exact to='/' activeClassName='nav-link-active'>
                    <button key='1' className='navbar-links-btn' onClick={this.props.logout()}>
                        <div className='navbar-links-btn-txt'>
                            Logout
                        </div>
                    </button>
                </NavLink>
            </div>
        );

        return (


                    <div className='phlog-manager-signout-route'>
                        {
                            isAuthenticated ? (logoutLink && phlogManagerLink) : (null)
                        }
                    </div>

                </div>  
            </div>
        );
    }
}

const mapStateToProps = state => {
    return {
        isAuthenticated: state.auth.token !== null
    };
};

const mapDispatchToProps = dispatch => {
  return {
    logout: () => dispatch(logout())
    // loggedIn: () => dispatch(actions.authCheckState())
  };
};


export default withRouter(
    connect(
        mapStateToProps,
        mapDispatchToProps
    ) (Navbar)
);

浏览器控制台始终提供以下警告消息:

检查道具ypes.js:20警告:失败的道具类型:无效的道具组件的类型对象提供给路由,预期的函数

做出反应。发展js:88警告:呈现不同组件(Navbar)时无法更新组件(ConnectFunction)。要在导航栏中找到错误的setState()调用,请按照中所述的堆栈跟踪


共有1个答案

阚英武
2023-03-14

用于导航的组件处理身份验证,但不处理登录状态。

 类似资料: