У меня есть приложение angular 8. И у меня есть директива с функциональностью внешней ссылки. Но если ссылка загружена на страницу, сделайте возврат страницы (перезагрузка страницы). Но, конечно, вы можете принудительно настроить routerLink, чтобы он не обновлял sh всю страницу.
Итак, у меня есть это:
@Directive({
selector: 'a[appExternalLink]'
})
/**
* This directive is responsible for checking if in Activity the link is a external link - then it wil open
* in a seperate tab or is the link an internal(same domain) link, then it will open in the same tab
*/
export class ExternalLinkDirective {
@HostBinding('rel') rel = '';
@HostBinding('target') target = '';
@Input()
@HostBinding('href')
href: string;
/**
* Check if liink is external or not
*/
ngOnChanges() {
const isExternal = this.isLinkExternal();
this.rel = isExternal ? 'noopener' : '';
this.target = isExternal ? '_blank' :'_self';
}
/**
* if link is external, then set the rel and target attributes
*/
private isLinkExternal() {
return !this.href.includes(location.hostname);
}
И шаблон, в котором я использую директиву:
<a appExternalLink
*ngIf= "activity.link; else nolink"
[href]="activity.link">
<div class="todo-day-part-subject">{{ activity.subject }}</div>
<div class="todo-day-part-block">
<div class="todo-day-part-icon {{ getIcon(activity.type) }}"></div>
<div class="todo-day-part-content">
<div class="todo-day-part-text">{{ activity.text }}</div>
<div class="todo-day-part-time">{{ activity.beginDate | date: 'HH:mm' }}</div>
<div *ngIf="activity.link" class="todo-day-part-readmore">Bekijk</div>
<div *ngIf="activity.state === 'Done'" class="todo-day-part-status-signal">
<span class="fa fa-check-circle"></span>
</div>
</div>
</div>
</a>
Но вот мой вопрос: куда я в этом случае положил routerLink? что страница не будет перезагружена
Спасибо