角2:如何确定与参数活动路线? [英] Angular 2: How to determine active route with parameters?

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

问题描述

我读过<一个href=\"http://stackoverflow.com/questions/34323480/in-angular-2-how-do-you-determine-the-active-route\">this有关如何确定活动路线,但仍然是我不清楚如何确定与PARAMATERS活跃的路由?问题

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??

推荐答案

只要勾选自动定义的路由器链路主动 A 元素。

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

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

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