Having trouble managing my parent-child state mostly as I am new to ui-router. However, I've done research and came across solutions that require hard-coding of routes but are not dynamic.
What I currently have:
<div> <!-- parent state -->
<div ng-if="'.' | isState">
<!--
background hierarchy that should be visible only when
parent state is active and not a child state of the parent
-->
</div>
<nav>
<a ui-sref="." ui-sref-active="active">Parent</a>
<a ui-sref=".child1" ui-sref-active="active">Child 1</a>
<a ui-sref=".child2" ui-sref-active="active">Child 2</a>
</nav>
<div ui-view></div>
</div>
What I'm trying to accomplish?
When the parent loads, I want the background to show something. It takes up the whole screen. The ui-view
will not take up the whole screen. As such, I want background element to be hidden or removed when route does not exactly match the parent's state (if parent's route is /root/parent
, I want background to be visible only when state is exactly /root/parent
and not /root/parent/child1
).
I am able to achieve what I want only when I provide the exact expected route. For example ng-if="'root.parent' | isState"
.
Also, ui-sref-active="active"
retains active
class when children views are shown (it is expected but I want the class only to be active when the route matches exactly).
However, I do not feel that it is good to hard-code route of the parent into view. I just want it to match whatever route it belongs to. As such, if I later decide to move it to /root/parent/car
, I shouldn't have to update ng-if
and ui-sref-active
to reflect the change.
Has anyone ran into the issue and was able to resolve it?