React JS - 从链接显示状态

问题描述 投票:1回答:1

我想从链接显示状态,如下所示:

<Link to={{ pathname: '/courses/product/productlist', state: { fromDashboard: true }}}> Food & Treats </Link>

如何在组件中显示状态?

reactjs react-router-v4
1个回答
0
投票

州将在location道具内部组件中提供。

访问这样的状态:

render(){
   console.log('state', this.props.location.state.fromDashboard);
   return (....)
}

查看Doc了解更多详情。

© www.soinside.com 2019 - 2024. All rights reserved.