Specifying animation when pushing new location with react-router

I’m using my own implementation of <IonPage>, most of it works exactly the same but the main difference are the “back” buttons. Those are pretty simple buttons:

        <button
          type="button"
          onClick={goBack}
        >
          {icon}
        </button>

goBack in this case is a prop which is usually either:

import { useHistory } from 'react-router-dom';
const history = useHistory()

history.goBack() or history.replace('/path/here')

In certain cases I want to replace so that the back button brings the user back to a main view rather than back in the stack of pages.

In these situations, the animations on the IonPage act as if a new element was pushed to the stack but I’d like to tell Ionic to use the goBack animation instead.

Is there any way to do this? The Router page in the docs seems really vague on the matter.

This page mentions that the Angular component has a push method that allows to specify a routerDirection. This is not mentioned on the React page.