From 859f94bf982a99447eb25e57ce623794d2a885a2 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 10 May 2024 14:38:02 +0200 Subject: [PATCH] MOBILE-4470 tabs: Fix route loaded when changing main menu tabs When using sub-routes like with core-tabs-outlet (e.g. participants), going back to the main menu tab set the main menu route as the current one instead of the sub-route and this caused problems with split view. --- src/core/components/tabs-outlet/tabs-outlet.ts | 9 +++++++++ src/core/singletons/path.ts | 18 ++++++++++++++++++ src/core/singletons/tests/path.test.ts | 9 +++++++++ 3 files changed, 36 insertions(+) diff --git a/src/core/components/tabs-outlet/tabs-outlet.ts b/src/core/components/tabs-outlet/tabs-outlet.ts index 0deddc47e..92c2d696d 100644 --- a/src/core/components/tabs-outlet/tabs-outlet.ts +++ b/src/core/components/tabs-outlet/tabs-outlet.ts @@ -30,6 +30,7 @@ import { StackDidChangeEvent } from '@ionic/angular/common/directives/navigation import { CoreNavigator } from '@services/navigator'; import { CoreTabBase, CoreTabsBaseComponent } from '@classes/tabs'; import { CoreDirectivesRegistry } from '@singletons/directives-registry'; +import { CorePath } from '@singletons/path'; /** * This component displays some top scrollable tabs that will autohide on vertical scroll. @@ -143,6 +144,14 @@ export class CoreTabsOutletComponent extends CoreTabsBaseComponent= pathSplit.length) { + return false; + } + + return !ancestorSplit.some((value, index) => value !== pathSplit[index]); + } + } diff --git a/src/core/singletons/tests/path.test.ts b/src/core/singletons/tests/path.test.ts index 9cee687e0..2800b79ef 100644 --- a/src/core/singletons/tests/path.test.ts +++ b/src/core/singletons/tests/path.test.ts @@ -52,4 +52,13 @@ describe('CorePath', () => { expect(CorePath.concatenatePaths('foo/bar', 'baz')).toEqual('foo/bar/baz'); }); + it('checks ancestor paths', () => { + expect(CorePath.pathIsAncestor('/foo', '/foo/bar')).toEqual(true); + expect(CorePath.pathIsAncestor('/foo/', '/foo/bar')).toEqual(true); + expect(CorePath.pathIsAncestor('/foo', '/foo/bar/baz')).toEqual(true); + expect(CorePath.pathIsAncestor('/foo/baz', '/foo/bar')).toEqual(false); + expect(CorePath.pathIsAncestor('/foo/bar', '/foo/bar')).toEqual(false); + expect(CorePath.pathIsAncestor('/foo/b', '/foo/bar')).toEqual(false); + }); + });