How to trigger a redirect to a given location with a given animation direction (say, back) in Ionic router without clicking a router link element?
There is a standard method to trigger a router redirect. The problem is that it can't change the animation direction so it's always forward:
// history is a value from react-router, it can be obtained from the HOC of the hook
history.push('/new/address');
There is also a method to go back, but it can't set a custom URL to go:
history.goBack();
I can also make a button and trigger a click on it, but it looks like an unwieldy solution:
const buttonRef = useRef();
const redirect = () => buttonRef.current.click();
return (
<IonButton
routerLink="/new/address"
routerDirection="back"
ref={buttonRef}
style={{display: 'none'}}
/>
);