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.main
parent
e511629b9c
commit
859f94bf98
|
@ -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<CoreTabsOutle
|
|||
// After the view has entered for the first time, we can assume that it'll always be in the navigation stack
|
||||
// until it's destroyed.
|
||||
this.existsInNavigationStack = true;
|
||||
|
||||
const selectedTab = this.getSelected();
|
||||
const currentPath = CoreNavigator.getCurrentPath();
|
||||
if (selectedTab && CorePath.pathIsAncestor(currentPath, selectedTab.page)) {
|
||||
// Current path is an ancestor of the selected path, this happens when the user changes main menu tab and comes back.
|
||||
// Load the tab again so the right route is loaded. This only changes the current route, it doesn't reload the page.
|
||||
this.loadTab(selectedTab);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -99,4 +99,22 @@ export class CorePath {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a certain path is the ancestor of another path.
|
||||
*
|
||||
* @param ancestorPath Ancestor path.
|
||||
* @param path Path to check.
|
||||
* @returns Whether the path is an ancestor of the other path.
|
||||
*/
|
||||
static pathIsAncestor(ancestorPath: string, path: string): boolean {
|
||||
const ancestorSplit = CoreText.removeEndingSlash(ancestorPath).split('/');
|
||||
const pathSplit = CoreText.removeEndingSlash(path).split('/');
|
||||
|
||||
if (ancestorSplit.length >= pathSplit.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !ancestorSplit.some((value, index) => value !== pathSplit[index]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue