# \[IGN-4947\]Prevent menu navigation by criteria

**URL:** <https://forum.inductiveautomation.com/t/ign-4947-prevent-menu-navigation-by-criteria/52247>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [October 22, 2021, 3:17pm UTC](https://forum.inductiveautomation.com/t/ign-4947-prevent-menu-navigation-by-criteria/52247 "2021-10-22T15:17:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mal](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mal](https://forum.inductiveautomation.com/u/mal)\
**Post date:** [October 22, 2021, 3:17pm UTC](https://forum.inductiveautomation.com/t/ign-4947-prevent-menu-navigation-by-criteria/52247/1 "2021-10-22T15:17:55Z")

</div>

Hi,

I have a perspective view that the user updates and the user needs to click save before the updates are sent to the database. If the user attempts to navigate away from the view after making an update, I would like a “Are you sure” pop-up to show and force the user to confirm before navigating away and/or take any action that wipes out their changes. I have created the pop-up and put that logic on the view (it checks a param and puts up the pop-up under specific criteria). However, when it comes to a menu-tree and browser navigation (back button, url change, etc) I don’t see a way to throw up this prompt.

This ends up being two questions:

- How do I block navigation on a menu tree component given a criteria?
- How do I block navigation at the browser given a criteria?

Preferably this would include some ability to script the response, so I can call up the pop-up and deal with that logic, but blocking would suffice.

Thanks

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 22, 2021, 4:02pm UTC](https://forum.inductiveautomation.com/t/ign-4947-prevent-menu-navigation-by-criteria/52247/2 "2021-10-22T16:02:48Z")

</div>

> [@mal](#):
>
> How do I block navigation at the browser given a criteria?

Right now, that's completely impossible in Perspective.  
To do so you need to add a `beforeunload` event handler in Javascript, and we deliberately don't expose any control over the javascript loaded on the page.  
It is an interesting idea though, so I filed a feature request for it.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 22, 2021, 4:19pm UTC](https://forum.inductiveautomation.com/t/ign-4947-prevent-menu-navigation-by-criteria/52247/3 "2021-10-22T16:19:22Z")

</div>

Even if you make it technically possible for Perspective, many browsers won’t honor that event. It has been historically abused to force eyeballs on advertisements. I recommend not relying on such nags.

---

<div class="post-metadata">

**Author:** ![mal](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mal](https://forum.inductiveautomation.com/u/mal)\
**Post date:** [October 25, 2021, 12:59pm UTC](https://forum.inductiveautomation.com/t/ign-4947-prevent-menu-navigation-by-criteria/52247/4 "2021-10-25T12:59:43Z")

</div>

Adding a beforeunload handler sounds great, thank you for submitting that.

Are there currently any hooks in the menu tree component to block or supercede a navigation request? I searched, asked colleagues, and tried a number of things, if not I would like to request a before navigation event that allows for cancelling navigation.

We have some ways of getting around this, IE creating our own embedded component, but other ideas are appreciated.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [October 25, 2021, 3:44pm UTC](https://forum.inductiveautomation.com/t/ign-4947-prevent-menu-navigation-by-criteria/52247/5 "2021-10-25T15:44:31Z")

</div>

The only way to hook into the navigation in Perspective and make any sort of conditional navigation is to create your own navigation View where everything ends up using a Script Action to determine whether the navigation should take place and if so where the user should be taken.

The Navigation category of components perform pure unchecked navigation without any way for a user to interrupt the process once a selection/click has been made.

One workaround you could examine is binding or recursively writing to the `enabled` property of each item in the navigation component based on whether the current submission has been saved/cleared.

---

<div class="post-metadata">

**Author:** ![mal](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mal](https://forum.inductiveautomation.com/u/mal)\
**Post date:** [October 26, 2021, 12:32pm UTC](https://forum.inductiveautomation.com/t/ign-4947-prevent-menu-navigation-by-criteria/52247/6 "2021-10-26T12:32:04Z")

</div>

Thanks, I was hoping there was a better way. The two options you mentioned are the same as what my team came up with, not very elegant, but they will work.

Can we put in a feature request for the ability to have conditional navigation functionality in navigation items?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [October 26, 2021, 1:57pm UTC](https://forum.inductiveautomation.com/t/ign-4947-prevent-menu-navigation-by-criteria/52247/7 "2021-10-26T13:57:28Z")

</div>

You could also just disable the Navigation Component until your condition is met.

---

<div class="post-metadata">

**Author:** ![mal](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mal](https://forum.inductiveautomation.com/u/mal)\
**Post date:** [October 26, 2021, 2:59pm UTC](https://forum.inductiveautomation.com/t/ign-4947-prevent-menu-navigation-by-criteria/52247/8 "2021-10-26T14:59:25Z")

</div>

That’s probably what we will go with, but it isn’t preferred from a UX perspective.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [October 26, 2021, 3:41pm UTC](https://forum.inductiveautomation.com/t/ign-4947-prevent-menu-navigation-by-criteria/52247/9 "2021-10-26T15:41:19Z")

</div>

I obviously don’t know your requirements, but from my perspective (no pun intended) as a user, I would much prefer that the component be disabled - as opposed to remaining enabled but some back-end logic preventing any action when I click it.

If your goal is to inform users that they can’t navigate due to some condition, you could always throw some logic into the onClick Event for the component and if the component is disabled you could open a popup informing the user as to why the component is disabled.

---

<div class="post-metadata">

**Author:** ![mal](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@mal](https://forum.inductiveautomation.com/u/mal)\
**Post date:** [October 26, 2021, 4:27pm UTC](https://forum.inductiveautomation.com/t/ign-4947-prevent-menu-navigation-by-criteria/52247/10 "2021-10-26T16:27:05Z")

</div>

> [@cmallonee](#):
>
> If your goal is to inform users that they can’t navigate due to some condition, you could always throw some logic into the onClick Event for the component and if the component is disabled you could open a popup informing the user as to why the component is disabled.

I am looking to do a pop-up to notify the user, but I also need the pop-up not to occur when the view isn't disabled... which I think I can do in script logic, that might actually work. Probably wouldn't be able to navigate per the user's request from the pop-up, but I could disable the navigation blocking from the pop-up and they can navigate from there. I will give that a shot, should be cleaner than other methods.
