Skip to content

Commit 5ee54ad

Browse files
vNovskiFrancescoMolinaro
authored andcommitted
[UXP-111] feature: carousel should use base url to check internal links
1 parent 258f739 commit 5ee54ad

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/app/shared/carousel/carousel.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<ngb-carousel #carousel [interval]="2000" (slide)="onSlide($event)" class="ds-carousel">
22
<ng-template ngbSlide *ngFor="let item of items; let i = index; let last = last">
33
<ng-container *ngIf="getItemLink(item.indexableObject); let currentLink; else carouselContent">
4-
<a *ngIf="isLinkInternal(currentLink)" [routerLink]="currentLink">
4+
<a *ngIf="isLinkInternal(currentLink)" [routerLink]="transformInternalLink(currentLink)">
55
<ng-container *ngTemplateOutlet="carouselContent"></ng-container>
66
</a>
77
<a *ngIf="!isLinkInternal(currentLink)" [href]="currentLink" [target]="carouselOptions.targetBlank ? '_blank' : null">

src/app/shared/carousel/carousel.component.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,29 @@ export class CarouselComponent implements OnInit {
158158
}
159159

160160
isLinkInternal(link: string) {
161-
return link.startsWith('/');
161+
const currentURL = window.location.origin;
162+
163+
if (link.startsWith('/')) {
164+
return true;
165+
}
166+
167+
if (link.startsWith(currentURL)) {
168+
link = link.substring(currentURL.length);
169+
return link.startsWith('/');
170+
}
171+
172+
return false;
173+
}
174+
175+
transformInternalLink(link: string): string {
176+
const currentURL = window.location.origin;
177+
178+
if (link.startsWith(currentURL)) {
179+
link = link.substring(currentURL.length);
180+
return link.startsWith('/') ? link : `/${link}`;
181+
}
182+
183+
return link;
162184
}
163185

164186
/**

0 commit comments

Comments
 (0)