Angular:如何使用参数确定活动路径? [英] Angular: How to determine active route with parameters?

查看:43
本文介绍了Angular:如何使用参数确定活动路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读有关如何确定有效路线,但是我仍然不清楚如何通过参数确定有效路线?

I've read this question about how to determine the active route, but still it's not clear to me how to determine an active route with paramaters?

现在我正在这样做:

<a [routerLink]="['/Profile/Feed', {username: username}]"
   [ngClass]="{active: getLinkStyle('/profile/john_doe/feed')}">
   Feed for {{username}}
</a>

在我的组件内部:

getLinkStyle(path:string):boolean {
  console.log(this._location.path()); // logs: '/profile/john_doe/feed'
  return this._location.path() === path;
}

这将起作用,因为我将用户名作为字符串传递.有没有办法通过传递正确的参数呢?

And this will work because I'm passing the username as a string. Is there any way to do this with passing the correct parameter??

推荐答案

只需检查自动定义的router-link-active类到a元素.

Just check the auto-defined router-link-active class to a element.

这篇关于Angular:如何使用参数确定活动路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆