CORD-833 Prevent duplication of navigation routes
Change-Id: Idbd797976080a3d7b29912950c687f1b0fcb67e1
diff --git a/src/app/core/services/navigation.ts b/src/app/core/services/navigation.ts
index 31f2b4e..e35c9f8 100644
--- a/src/app/core/services/navigation.ts
+++ b/src/app/core/services/navigation.ts
@@ -18,10 +18,11 @@
}
export class NavigationService {
- static $inject = ['StyleConfig'];
+ static $inject = ['$log', 'StyleConfig'];
private routes: IXosNavigationRoute[];
constructor(
+ private $log: ng.ILogService,
private StyleConfig: IXosStyleConfig
) {
const defaultRoutes = [
@@ -51,6 +52,18 @@
throw new Error('[XosNavigation] You can\'t provide both state and url');
}
+ const routeExist = _.findIndex(this.routes, (r: IXosNavigationRoute) => {
+ if (r.label === route.label && r.state === route.state && r.parent === route.parent) {
+ return true;
+ }
+ return false;
+ }) > -1;
+
+ if (routeExist) {
+ this.$log.warn(`[XosNavigation] Route with label: ${route.label}, state: ${route.state} and parent: ${route.parent} already exist`);
+ return;
+ }
+
if (angular.isDefined(route.parent)) {
// route parent should be a state for now