Issue
I have a route setup like so:
<Route path={'/mycomponent'} exact component={MyComponent} />
and navigate to it using an ActiveLink component:
import * as React from 'react' import { Link } from 'react-router-dom'
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
I would like to find a way to pass data to 'MyComponent' (preferably in the props), something that is the equivalent of '/MyComponent?aparam=hello&anotherparam=32'
Solution
Let say you have below route that you explained.
<Route path={'/mycomponent'} exact component={MyComponent} />
Now if you redirect on route let's say
MyComponent?aparam=hello&anotherparam=32
So in you MyComponent class you can get that both parameters like below
let aparam = this.props.match.params.aparam;
let anotherparam = this.props.match.params.anotherparam;
Hope this will help, if not then please elaborate more about your question Thnaks :)
Answered By - Binit Ghetiya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.