React native 从链接获取道具对象
如何做到这一点?例如,我发现:React native 从链接获取道具对象,react-native,react-router-native,React Native,React Router Native,如何做到这一点?例如,我发现: <Link to={{pathname: "/dialog", state: { detail: message }}}> text </Link> 文本 但是如果我想显示这个.props.location.state,那么就写未定义的传递参数 Configure your route path to accept named parameters (:id): <Route path='/route/:id' exact c
<Link to={{pathname: "/dialog", state: { detail: message }}}>
text
</Link>
文本
但是如果我想显示这个.props.location.state,那么就写未定义的传递参数
Configure your route path to accept named parameters (:id):
<Route path='/route/:id' exact component={MyComponent} />
Then you can pass URL parameters such as IDs in your link to:
<Link to={`route/foo`}>My route</Link>
You can access the parameter within your component via the match object:
const {id} = props.match.params
console.log(id) // "foo"
配置路由路径以接受命名参数(:id):
然后,您可以将URL参数(如链接中的ID)传递到:
我的路线
您可以通过匹配对象访问组件中的参数:
const{id}=props.match.params
console.log(id)/“foo”
}/>
和
,消息是对象,但即使字符串也不传递参数。