【问题标题】:React-router - how to use route params in onEnter?React-router - 如何在 onEnter 中使用路由参数?
【发布时间】:2016-09-09 18:54:41
【问题描述】:

我想使用 onEnter 回调进行提取,但我不知道如何读取 Route 组件中的 URL 参数。 我有这条路线

<Route path="book/:bookId" component={BookContainer} onEnter={onBookLoad()}/>

我想使用路径中的bookId 作为onBookLoad() 的函数参数。有可能吗?

【问题讨论】:

标签: react-router


【解决方案1】:

没关系,这是微不足道的。

<Route path="book/:bookId" component={BookContainer} onEnter={onBookLoad}/>

export function onBookLoad(nextState) {
 console.log(nextState.params.bookId);
 //do stuff with the param
}

【讨论】:

  • 您的意思是 bookId,而不是surveyId?
猜你喜欢
  • 2016-11-06
  • 2016-08-07
  • 2017-08-03
  • 2023-03-12
  • 2016-09-13
  • 1970-01-01
  • 1970-01-01
  • 2022-11-29
  • 1970-01-01
相关资源
最近更新 更多