首页 > 解决方案 > TypeError:无法读取未定义反应的属性“url”

问题描述

有人可以帮忙吗?我得到了文件 AddPost.js

</div>
                            {this.props.admin.post.PostImage ?
                                <img src={API.makeFileURL(this.props.admin.post.PostImage[0].url, this.props.auth.token)} className="post-image" /> 
                            : null}
                            <div>
                                <Button
                                    variant="contained" 
                                    color="primary"
                                    onClick={e => {
                                        $('.MyFile').trigger('click'); 
                                    }}
                                ><ImageIcon />Upload Post Image</Button>
                                <input type="file" style={{display: 'none'}} className="MyFile" onChange={this.uploadImage}/>
                            </div>

API 文件包含此功能:

makeFileURL: (url, token) => {
        return host + url + "?access_token" + token;
    }

标签: reactjs

解决方案


import {Link,Route} from 'react-router-dom';
export const Category = ({match}) => {
    return (
        <div>
            <ul>
                <li><Link to={`${match.url}/mobile`} >Mobile</Link></li>
                <li><Link to={`${match.url}/laptop`} >Laptop</Link></li>
                <li><Link to={`${match.url}/shoes`} >Shoes</Link></li>
            </ul>
           
        </div>
    )
}

在这种情况下,任何人都会收到错误“TypeError:无法读取未定义的属性'url'”,因此需要更改

<Route path='/category' component={Category} />

推荐阅读