Issue
The below onClick() function works as intended without href. But when I add in the href, only the href seems to run, not the onClick() function. How do I both run the onClick() function and also send the user to a new page?
<IonButton
color="primary"
onClick={() => {saveData()}}
href="/create/"
>Save</IonButton>
Solution
you do not really want to use href
use history
const history = useHistory();
<IonButton color="primary"
onClick={(event) => {
event.preventDefault();
saveData();
history.push("/create")}}
> Save
</IonButton>
Answered By – Aaron Saunders
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0