# beforePageChange plugin API?

**URL:** https://meta.discourse.org/t/beforepagechange-plugin-api/212246
**Category:** Development
**Created:** [December 15, 2021, 9:12pm UTC](https://meta.discourse.org/t/beforepagechange-plugin-api/212246 "2021-12-15T21:12:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hrayner](https://avatars.discourse-cdn.com/v4/letter/h/5f9b8f/32.png) [@hrayner](https://meta.discourse.org/u/hrayner)
#### Post date: [December 15, 2021, 9:12pm UTC](https://meta.discourse.org/t/beforepagechange-plugin-api/212246/1 "2021-12-15T21:12:49Z")

</div>

Is there a plugin-API for before a new page is loaded / while a page is loading?

I have a problem where I’m changing styles on the navbar depending on the page by using the onPageChange API. Unfortunately this means that when someone is navigating around my site, the navbar changes are not taking place until the new page is loaded. So going from a page where I have a transparent navbar to a page where I have a solid one, the transparent navbar is visible until the new page has completed loading (i.e. while the spinner is present). This is a bad look so I’m looking for a solution.

Any suggestions would be greatly appreciated. Thank you!

---

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [December 15, 2021, 9:26pm UTC](https://meta.discourse.org/t/beforepagechange-plugin-api/212246/2 "2021-12-15T21:26:58Z")

</div>

Have a look here

[Trigger javascript on clicking any page link, but before the page content loads? - #2 by Johani](https://meta.discourse.org/t/trigger-javascript-on-clicking-any-page-link-but-before-the-page-content-loads/167970/2)

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.
