2
我已經創建,其接收在其上的選擇器設置性能的組分:角2個鏈接到外部的URL當作相對路徑用於路由
<app-navigation-card
label="My Label"
description="Description of Item"
type="download"
[links]="[{path:'https://somedomain.com/somefile.zip', label:'Download'}]"
></app-navigation-card>
輸入被設置在NavigationCard類:
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-navigation-card',
templateUrl: './navigation-card.component.html',
styleUrls: ['./navigation-card.component.scss']
})
export class NavigationCardComponent implements OnInit {
@Input() label: String;
@Input() description: String;
@Input() links: Object;
@Input() type: String;
constructor() { }
ngOnInit() {
}
}
在模板:
<div class="label">{{label}}</div>
<div class="description">{{description}}</div>
<ul *ngIf="links != undefined" class="links">
<li *ngFor="let link of links" [routerLink]="link.path">
<span *ngIf="type == 'download'"><a href="{{link.path}}">{{link.label}}</a></span>
<span *ngIf="type == 'navigation'" [routerLink]="link.path"><{{link.label}}</span>
<div></div>
</li>
</ul>
如果類型== navigation
,路由器重定向到正確的成分,但是當它是一個下載,我得到這個錯誤:在鏈接的href明確輸入時,而不是通過屬性綁定
EXCEPTION: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'style-guide/https%3A/somedomain.com/somefile.zip'
這個URL工作正常。任何想法如何彌補這一點?
從我的理解,這繞開了內部路由(SPA)的全部目的,實質上是在所述URL處對網站的新命中。 –
@ChrisWhite這是路由器不應該知道這個外部URL導航的具體情況,因爲我們使用了'href' .. –