根据条件使用 routerlink 或 href

Use routerlink or href based on condition

我在组件中有这段代码

<a *ngFor="let item of config.socialLinks" [routerLink]="[item.url]">
...
</a>

这在使用 app.component 中定义的本地路由时按预期工作,但在外部路由时它重定向到 http:localhost:5555 | http://external.com 有没有办法对本地路由使用 routerLink,对外部路由使用 href?

那是因为,指令[routerLink]只针对内部路由系统,外部链接应该在href中这样声明:

<a *ngFor="let item of config.socialLinks" href="{{item.url}}"></a>

尽情享受吧。