问题描述
这是我试图运行的代码:
import { withRouter } from 'found';
const routetoUrl = props => props.router.push(props.path);
export default withRouter(routetoUrl);
withRouter是catalyzer/found
的HOC,如上面的路由组件一样,包装现有的组件类或函数并注入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在上层上下文中需要路由器
您需要重定向组件还是只需要使用location.path?