# Hide nav btn on route changes

**URL:** <https://discuss.elastic.co/t/hide-nav-btn-on-route-changes/110936>\
**Category:** Kibana\
**Created:** [December 9, 2017, 4:51pm UTC](https://discuss.elastic.co/t/hide-nav-btn-on-route-changes/110936 "2017-12-09T16:51:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jetpumz](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@jetpumz](https://discuss.elastic.co/u/jetpumz)\
**Post date:** [December 9, 2017, 4:51pm UTC](https://discuss.elastic.co/t/hide-nav-btn-on-route-changes/110936/1 "2017-12-09T16:51:16Z")

</div>

I create a button for visualize and put it on navigation bar

```
import { NavBarExtensionsRegistryProvider } from 'ui/registry/navbar_extensions';
import chrome from 'ui/chrome';

function visualizeControlProvider($http) {
   return {
     appName: 'visualize',
     key: 'visualize-extra-button',
     label: 'Extra',
     run: (elm, prop) => {},
     hideButton: false // This is the problem
   };
}

NavBarExtensionsRegistryProvider.register(($http) => {
   return visualizeControlProvider($http);
});

```

The issue is, I want to dynamically hide the button upon route changes. So I want to hide the button if it's on the grid list view of visualize while show the button when on edit/create mode.

Been trying to use $onRouteChanges, but didn't work

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [December 12, 2017, 2:17pm UTC](https://discuss.elastic.co/t/hide-nav-btn-on-route-changes/110936/2 "2017-12-12T14:17:09Z")

</div>

Hey @jetpumz, if you inject the `$location` service you can use a function for `hideButton` to determine if it's visible or not.

Something like this should work:

```auto
import { NavBarExtensionsRegistryProvider } from 'ui/registry/navbar_extensions';
import chrome from 'ui/chrome';

function visualizeControlProvider($http, $location) {
   return {
     appName: 'visualize',
     key: 'visualize-extra-button',
     label: 'Extra',
     run: (elm, prop) => {},
     hideButton: () => {
       return $location.path() === `/visualize`;
     }
   };
}

NavBarExtensionsRegistryProvider.register(($http) => {
   return visualizeControlProvider($http);
});

```

---

<div class="post-metadata">

**Author:** ![jetpumz](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@jetpumz](https://discuss.elastic.co/u/jetpumz)\
**Post date:** [December 18, 2017, 1:59pm UTC](https://discuss.elastic.co/t/hide-nav-btn-on-route-changes/110936/3 "2017-12-18T13:59:45Z")

</div>

Hi @Brandon_Kobel Thanks for the reply, actually I managed to do it using

`getAppState()`

service that kibana has. But thanks for the feedback !

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 15, 2018, 1:59pm UTC](https://discuss.elastic.co/t/hide-nav-btn-on-route-changes/110936/4 "2018-01-15T13:59:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
