我想用相对的routerlink实现这样的东西:
[routerLink]=[routePart, 'Create']
其中routePart是一个组件属性,可以为空,这意味着它应该被忽略,或者有一些值
因此,如果当前路线是'/ Products',那么如果
routePart =''我们想得到'/ Products / Create'
routePart ='xyz'我们想获得'/ Product / xyz / Create'
但是我在第一种情况下发现它变成了一条绝对的路径并且解析为'/ Create'
我可以使用绑定中的表达式来使用它,但这看起来有点难看
[routerLink]='routePart == '' ? 'Create' : 'xyz/Create''
是否有一些干净的方法让这个工作?
试试这个。
<a *ngIf="routePart === '' " [routerLink]="Create" />
<a *ngIf="routePart === 'xyz' " [routerLink]="xyz/Create" />