Listing 12-15: Viewing properties of the current location object
Current Location
- pathname: /listing1215
- hash:
- search:
- key:
import React from "react";
import {
withRouter
} from "react-router-dom";
function ViewLocation(props) {
return (
<>
<h1>Current Location</h1>
<ul>
<li>pathname: {props.location.pathname}</li>
<li>hash: {props.location.hash}</li>
<li>search: {props.location.search}</li>
<li>key: {props.location.key}</li>
</ul>
</>
);
}
export default withRouter(ViewLocation);
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.