Listing 12-7: Using the component attribute
Order #4import React from "react";
import {
BrowserRouter as Router,
Route,
Link
} from "react-router-dom";
function ComponentProp(props) {
const OrderDetails = (props)=>{
return (
<h1>Details for order # {props.match.params.orderid}</h1>
)
}
return (
<>
<Router>
<Link to="/orders/4">Order #4</Link>
<Route path="/orders/:orderid" component={OrderDetails} />
</Router>
</>
);
}
export default ComponentProp;
Download the examples, report issues, and ask/answer questions in the discussion area by visiting the book's github page. All of the code for the book is also available on codesandbox.io for you to play around with.
ReactJS Foundations is published by John Wiley and Sons, Inc and is available in paperback and eBook.