【发布时间】:2018-06-11 10:59:01
【问题描述】:
我有这样的路线设置:
<Route path={'/mycomponent'} exact component={MyComponent} />
并使用 ActiveLink 组件导航到它:
import * as React from 'react' 从 'react-router-dom' 导入 { Link }
export interface OwnProps {
to : string,
pathname : string,
children : React.ReactChild
}
const ActiveLink = (props: OwnProps) => {
const { pathname, to, children } = props
if (pathname === to) {
return <span className={ 'active-link active' }>{ children }</span>
} else {
return <Link className={ 'active-link in-active' } to={ to ? to : '/' }>{ children }</Link>
}
}
export default ActiveLink
我想找到一种方法将数据传递给“MyComponent”(最好在道具中),它相当于“/MyComponent?aparam=hello&anotherparam=32”
【问题讨论】:
-
顺便说一句,如果你的组件不是某个路由的直接后代,当你可以用 withRouter() 包装它并传递给它的相同道具时
标签: reactjs typescript routes react-router react-redux