Reputation: 2112
I have this Test
as react component which is having a link book
.When I click this link I want to open a new tab with url /book-data
and render Book
component.Also I have to pass book_id
from Test
to Book
as Book
is showing this data.
class Test extends React.Component {
render() {
const book_id = 123;
return (
<div>
<a href="/book-data">book</a>
</div>
)
}
}
export default Test;
Book
component showing book_id
import React from "react";
class Book extends React.Component {
render() {
return (
<div>
{this.props.book_id}
</div>
)
}
}
export default Book;
Upvotes: 2
Views: 171
Reputation: 221
Define your Route something like this:
<Route path="book-data/:id" component={Book} />
Then from Test
Component render Book
Component
render() {
const book_id = 123;
return (
<div>
<a href="/book-data/{book_id}">book</a>
</div>
)
}
Now in Book
Component you can get book_id
like this:
componentDidMount(){
var book_id = this.props.params.id;
}
Upvotes: 1