Question: I am using react router and I have the following code:

```
let history = useHistory();

let goToReviewPage = () => history.push(`review/${productId}`);

```

My current url is: `/foo/bar` and calling `goToReviewPage()` will redirect me to

`/foo/review/${productId}` instead of `/foo/bar/review/${productId}`

I am not sure how to set the base path will pushing the history.

Answer: 
You can use React Router's `match.url`. Example:

```
const Component = ({ productId }) => {
  const match = useRouteMatch();
  const history = useHistory();

  const handleClick = () => {
    history.push(`${match.url}/review/${productId}`);
  };

  return (
    <button onClick={handleClick}>Click me</button>
  );
};

```
One way is to use `window.location` to obtain the current path.

For example:

```
history.push(window.location.pathname + '/' + `review/${productId}`);

```

[**window.location api**](https://www.w3schools.com/js/js_window_location.asp)