Have a look here
Trigger javascript on clicking any page link, but before the page content loads? - #2 by Johani
Generally, though, onPageChange
should be avoided if you can. There’s other ways to check the current route and do some conditional work based on that. Happy to take a look if you post your code and desired result here.