2015-09-14 15:01:08 -07:00
p.location-badge.
exported from <a href='../router'>angular2/router</a>
defined in <a href="https://github.com/angular/angular/tree/2.0.0-alpha.37/modules/angular2/src/router/router_link.ts#L6-L72">angular2/src/router/router_link.ts (line 6)</a>
:markdown
2015-09-16 23:40:23 -07:00
The RouterLink directive lets you link to specific parts of your app.
Consider the following route configuration:
```
@RouteConfig([
{ path: '/user', component: UserCmp, as: 'user' }
]);
class MyComp {}
```
When linking to this `user` route, you can write:
```
<a [router-link]="['./user']">link to user component</a>
```
RouterLink expects the value to be an array of route names, followed by the params
for that level of routing. For instance `['/team', {teamId: 1}, 'user', {userId: 2}]`
means that we want to generate a link for the `team` route with params `{teamId: 1}`,
and with a child route `user` with params `{userId: 2}`.
The first route name should be prepended with `/`, `./`, or `../`.
If the route begins with `/`, the router will look up the route from the root of the app.
If the route begins with `./`, the router will instead look in the current component's
children for the route. And if the route begins with `../`, the router will look at the
current component's parent.
2015-09-14 15:01:08 -07:00
.l-main-section
h2 Annotations
.l-sub-section
h3.annotation Directive
pre.prettyprint
code.
@Directive({
selector: '[router-link]',
properties: ['routeParams: routerLink'],
host: {
'(click)': 'onClick()',
'[attr.href]': 'visibleHref',
'[class.router-link-active]': 'isRouteActive'
}
})
.l-main-section
h2 Members
.l-sub-section
2015-09-16 23:40:23 -07:00
h3#constructor constructor
2015-09-14 15:01:08 -07:00
pre.prettyprint
code.
constructor(_router: Router, _location: Location)
:markdown
.l-sub-section
2015-09-16 23:40:23 -07:00
h3#visibleHref visibleHref
2015-09-14 15:01:08 -07:00
:markdown
.l-sub-section
2015-09-16 23:40:23 -07:00
h3#isRouteActive isRouteActive
2015-09-14 15:01:08 -07:00
:markdown
.l-sub-section
2015-09-16 23:40:23 -07:00
h3#routeParams routeParams
2015-09-14 15:01:08 -07:00
:markdown
.l-sub-section
2015-09-16 23:40:23 -07:00
h3#onClick onClick
2015-09-14 15:01:08 -07:00
pre.prettyprint
code.
onClick()
:markdown