thingsboard-memoizeit

Details

diff --git a/ui/src/app/dashboard/states/default-state-controller.js b/ui/src/app/dashboard/states/default-state-controller.js
index 0dfe229..fb02147 100644
--- a/ui/src/app/dashboard/states/default-state-controller.js
+++ b/ui/src/app/dashboard/states/default-state-controller.js
@@ -154,8 +154,18 @@ export default function DefaultStateController($scope, $timeout, $location, $sta
             result = newResult;
         }
 
+        var rootStateId = dashboardUtils.getRootStateId(vm.states);
         if (!result[0].id) {
-            result[0].id = dashboardUtils.getRootStateId(vm.states);
+            result[0].id = rootStateId;
+        }
+        if (!vm.states[result[0].id]) {
+            result[0].id = rootStateId;
+        }
+        var i = result.length;
+        while (i--) {
+            if (!result[i].id || !vm.states[result[i].id]) {
+                result.splice(i, 1);
+            }
         }
         return result;
     }
diff --git a/ui/src/app/dashboard/states/entity-state-controller.js b/ui/src/app/dashboard/states/entity-state-controller.js
index 11017a8..cfa664d 100644
--- a/ui/src/app/dashboard/states/entity-state-controller.js
+++ b/ui/src/app/dashboard/states/entity-state-controller.js
@@ -205,6 +205,15 @@ export default function EntityStateController($scope, $timeout, $location, $stat
         if (!result[0].id) {
             result[0].id = rootStateId;
         }
+        if (!vm.states[result[0].id]) {
+            result[0].id = rootStateId;
+        }
+        var i = result.length;
+        while (i--) {
+            if (!result[i].id || !vm.states[result[i].id]) {
+                result.splice(i, 1);
+            }
+        }
         return result;
     }