[英]Can we wrap non react functions with 4Catalyzer/found's 'withRouter' HOC?
這是我試圖運行的代碼:
import { withRouter } from 'found';
const routeToUrl = props => props.router.push(props.path);
export default withRouter(routeToUrl);
其中 withRouter 是來自catalyzer/found
的 HOC 包裝現有組件 class 或 function 並注入match
和router
道具,就像上面的路由組件一樣。 您可以使用此 HOC 創建在事件處理程序中以編程方式導航的組件。 https://github.com/4Catalyzer/found#programmatic-navigation
我對route components
的含義有點不清楚。 routeToUrl
不是路由組件是它不起作用的原因嗎?
收到錯誤:
react.development.js?99ee:428 Uncaught (in promise) TypeError: Cannot set property 'props' of undefined
at Component (react.development.js?99ee:428)
at withRouter(routeToUrl) (connectAdvanced.js?4805:109)
謝謝!
withRouter 在上層上下文中需要 Router
您需要重定向組件還是只需要使用 location.path?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.