[英]Angular 7 routerlink with FIXED parts
I need to create an new link from the current route: 我需要从当前路线创建一个新链接:
https://website.com/post/99 = curent browser route https://website.com/post/99 =当前的浏览器路由
and I need to create this: 我需要创建这个:
https://website.com/ admin /post/99/ edit https://website.com/ 管理员 / post / 99 / 编辑
How to add "admin" and "edit" to this route on angular 7 ? 如何在Angular 7的此路由上添加“ admin”和“ edit”?
<a [routerLink]="admin/['./']/edit">Edit</a>
You could create a method in your component : 您可以在组件中创建一个方法:
constructor(private route: ActivatedRoute) {}
getAdminUrl(): string {
return [
'/admin',
'post',
this.route.snapshot.paramMap.get('postId'), // Change with the route parameter id
'edit',
];
}
And use it in your template : 并在您的模板中使用它:
<a [routerLink]="getAdminUrl()">Edit</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.