React-router - 如何在 onEnter 中使用路由参数? [英] React-router - how to use route params in onEnter?
本文介绍了React-router - 如何在 onEnter 中使用路由参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 onEnter 回调进行提取,但我不知道如何读取 Route 组件中的 URL 参数.我有这条路线
I want to do a fetch using the onEnter callback, but I don't know how to read a URL param in the Route component. I have this Route
<Route path="book/:bookId" component={BookContainer} onEnter={onBookLoad()}/>
我想使用路径中的 bookId
作为 onBookLoad()
的函数参数.可能吗?
I want to use the bookId
from path as function parameter for onBookLoad()
. Is it possible?
推荐答案
没关系,这是微不足道的.
Nevermind, it was trivial.
<Route path="book/:bookId" component={BookContainer} onEnter={onBookLoad}/>
export function onBookLoad(nextState) {
console.log(nextState.params.bookId);
//do stuff with the param
}
这篇关于React-router - 如何在 onEnter 中使用路由参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文