Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
68
rated 0 times [  69] [ 1]  / answers: 1 / hits: 22044  / 7 Years ago, wed, april 5, 2017, 12:00:00
<Link to=/promospace/detail>
<div className=card>
/* content */
</div>
</Link>


I can't do above, no error but it just doesn't work. Any clue how to wrap div within Link? Or I have to bind it to a click handler? Can't use Link in jsx?


More From » reactjs

 Answers
4

Use a span inside your link, and set display: block on it as well, that will definitely work everywhere, and it will validate!



<Link to=/promospace/detail>
<span className=card style={{display: block}}>
/* content */
</span>
</Link>


Or else you can do dynamic routing on an onClick event



changeRoute = () => {
this.context.router.push('/promospace/detail');
}
......
<div className=card onClick={this.changeRoute}>
/* content */
</div>

....
MyComponent.contextTypes = {
router: React.PropTypes.func.isRequired
}

[#58267] Monday, April 3, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aidan

Total Points: 72
Total Questions: 95
Total Answers: 121

Location: Uzbekistan
Member since Sat, Feb 27, 2021
3 Years ago
aidan questions
Mon, Oct 11, 21, 00:00, 3 Years ago
Wed, Sep 29, 21, 00:00, 3 Years ago
Sun, Sep 5, 21, 00:00, 3 Years ago
Thu, Jan 16, 20, 00:00, 4 Years ago
;