From e8e5aa28c5d934b3ce2deb8ce6d67e1fc04e9640 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Tue, 28 Apr 2020 14:51:38 +0300 Subject: [PATCH] fix(core): resolve wrapper routes duplication problem resolves #3703 --- .../core/src/lib/plugins/config.plugin.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/plugins/config.plugin.ts b/npm/ng-packs/packages/core/src/lib/plugins/config.plugin.ts index f9c8f45423..b2afab6072 100644 --- a/npm/ng-packs/packages/core/src/lib/plugins/config.plugin.ts +++ b/npm/ng-packs/packages/core/src/lib/plugins/config.plugin.ts @@ -10,7 +10,7 @@ import { } from '@ngxs/store'; import clone from 'just-clone'; import snq from 'snq'; -import { ABP } from '../models'; +import { ABP } from '../models/common'; import { getAbpRoutes, organizeRoutes } from '../utils/route-utils'; export const NGXS_CONFIG_PLUGIN_OPTIONS = new InjectionToken('NGXS_CONFIG_PLUGIN_OPTIONS'); @@ -30,8 +30,8 @@ export class ConfigPlugin implements NgxsPlugin { if (isInitAction && !this.initialized) { const transformedRoutes = transformRoutes(this.router.config); - let { routes } = transformedRoutes; - const { wrappers } = transformedRoutes; + let { routes, wrappers } = transformedRoutes; + wrappers = reduceWrappers(wrappers); routes = organizeRoutes(routes, wrappers); const flattedRoutes = flatRoutes(clone(routes)); @@ -118,3 +118,14 @@ function flatRoutes(routes: ABP.FullRoute[]): ABP.FullRoute[] { return flat(routes); } + +function reduceWrappers(wrappers: ABP.FullRoute[] = []) { + const existingWrappers = new Set(); + + return wrappers.filter(wrapper => { + if (existingWrappers.has(wrapper.name)) return false; + + existingWrappers.add(wrapper.name); + return true; + }); +}