diff --git a/src/app/components/preview/preview.component.spec.ts b/src/app/components/preview/preview.component.spec.ts index 75cff1615..f8c7e150e 100644 --- a/src/app/components/preview/preview.component.spec.ts +++ b/src/app/components/preview/preview.component.spec.ts @@ -205,7 +205,7 @@ describe('PreviewComponent', () => { component.onVisibilityChanged(false); expect(router.navigate).toHaveBeenCalledWith( - ['libraries'] + ['libraries', {}] ); }); @@ -219,7 +219,7 @@ describe('PreviewComponent', () => { component.onVisibilityChanged(false); expect(router.navigate).toHaveBeenCalledWith( - ['libraries', 'site1'] + ['libraries', {}, 'site1'] ); }); @@ -233,7 +233,7 @@ describe('PreviewComponent', () => { component.onVisibilityChanged(false); expect(router.navigate).toHaveBeenCalledWith( - ['shared'] + ['shared', {}] ); }); diff --git a/src/app/components/preview/preview.component.ts b/src/app/components/preview/preview.component.ts index 6ff4e806e..1a84f6b50 100644 --- a/src/app/components/preview/preview.component.ts +++ b/src/app/components/preview/preview.component.ts @@ -24,7 +24,7 @@ */ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; +import { ActivatedRoute, Router, UrlTree, UrlSegmentGroup, UrlSegment, PRIMARY_OUTLET } from '@angular/router'; import { AlfrescoApiService, UserPreferencesService, ObjectUtils } from '@alfresco/adf-core'; import { Node, MinimalNodeEntity } from 'alfresco-js-api'; import { NodePermissionService } from '../../common/services/node-permission.service'; @@ -124,7 +124,7 @@ export class PreviewComponent implements OnInit { const shouldSkipNavigation = this.routesSkipNavigation.includes(this.previewLocation); if (!isVisible) { - const route = [this.previewLocation]; + const route = this.getNavigationCommands(this.previewLocation); if ( !shouldSkipNavigation && this.folderId ) { route.push(this.folderId); @@ -333,4 +333,20 @@ export class PreviewComponent implements OnInit { } catch { } } + + private getNavigationCommands(url: string): any[] { + const urlTree: UrlTree = this.router.parseUrl(url); + const urlSegmentGroup: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET]; + + if (!urlSegmentGroup) { + return [url]; + } + + const urlSegments: UrlSegment[] = urlSegmentGroup.segments; + + return urlSegments.reduce(function(acc, item) { + acc.push(item.path, item.parameters); + return acc; + }, []); + } }