Skip to content

Commit 65d17c8

Browse files
committed
Merge pull request #153 from NativeScript/feature/is-route-active
Implemented isRouteActive property of nsRouterLink
2 parents e3b00bb + 7768310 commit 65d17c8

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

Diff for: ng-sample/app/app.ts

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {NavigationTest} from "./examples/navigation/navigation-test";
2525
import {ActionBarTest} from "./examples/action-bar/action-bar-test";
2626
import {ModalTest} from "./examples/modal/modal-test";
2727
import {PlatfromDirectivesTest} from "./examples/platform-directives/platform-directives-test";
28+
import {RouterOutletTest} from "./examples/navigation/router-outlet-test";
2829

2930
nativeScriptBootstrap(RendererTest);
3031
//nativeScriptBootstrap(Benchmark);
@@ -38,3 +39,4 @@ nativeScriptBootstrap(RendererTest);
3839
// nativeScriptBootstrap(ActionBarTest, [NS_ROUTER_PROVIDERS], { startPageActionBarHidden: false });
3940
// nativeScriptBootstrap(ModalTest);
4041
// nativeScriptBootstrap(PlatfromDirectivesTest);
42+
// nativeScriptBootstrap(RouterOutletTest, [NS_ROUTER_PROVIDERS]);
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.title {
2+
font-size: 30;
3+
margin: 16;
4+
color: darkslategray;
5+
}
6+
7+
.nav {
8+
orientation: horizontal;
9+
horizontal-align: stretch;
10+
padding: 4;
11+
background-color: lightblue;
12+
}
13+
14+
.link {
15+
margin: 10 30;
16+
horizontal-align: stretch;
17+
}
18+
19+
.router-link-active {
20+
background-color: lightcoral;
21+
}
22+
23+
button {
24+
horizontal-align: left;
25+
margin: 0 6;
26+
}
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {Component} from 'angular2/core';
2+
import {RouteConfig, ROUTER_PROVIDERS, ROUTER_DIRECTIVES, ComponentInstruction, RouteParams} from 'angular2/router';
3+
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "../../nativescript-angular/router/ns-router";
4+
5+
@Component({
6+
selector: "first",
7+
directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
8+
styleUrls: ["examples/navigation/router-outlet-test.css"],
9+
template: `
10+
<StackLayout>
11+
<Label text="First component" class="title"></Label>
12+
</StackLayout>`
13+
})
14+
class FirstComponent { }
15+
16+
@Component({
17+
selector: "second",
18+
directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
19+
styleUrls: ["examples/navigation/router-outlet-test.css"],
20+
template: `
21+
<StackLayout>
22+
<Label [text]="'Second component - ' + id" class="title"></Label>
23+
</StackLayout>`
24+
})
25+
class SecondComponent {
26+
public id: string;
27+
constructor(routeParams: RouteParams) {
28+
this.id = routeParams.get("id");
29+
}
30+
}
31+
32+
@Component({
33+
selector: 'navigation-test',
34+
directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
35+
styleUrls: ["examples/navigation/router-outlet-test.css"],
36+
template: `
37+
<StackLayout>
38+
<StackLayout class="nav">
39+
<Button text="First" [nsRouterLink]="['First']"></Button>
40+
<Button text="GO(1)" [nsRouterLink]="['Second', { id: 1 }]"></Button>
41+
<Button text="GO(2)" [nsRouterLink]="['Second', { id: 2 }]"></Button>
42+
<Button text="GO(3)" [nsRouterLink]="['Second', { id: 3 }]"></Button>
43+
</StackLayout>
44+
45+
<router-outlet></router-outlet>
46+
</StackLayout>
47+
`
48+
})
49+
@RouteConfig([
50+
{ path: '/first', component: FirstComponent, name: 'First', useAsDefault: true },
51+
{ path: '/second/:id', component: SecondComponent, name: 'Second' },
52+
])
53+
export class RouterOutletTest { }

Diff for: src/nativescript-angular/router/ns-router-link.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ import { log } from "./common";
3535
selector: '[nsRouterLink]',
3636
inputs: ['params: nsRouterLink'],
3737
host: {
38-
'(tap)': 'onTap()'
38+
'(tap)': 'onTap()',
39+
'[class.router-link-active]': 'isRouteActive'
3940
}
4041
})
4142
export class NSRouterLink {
@@ -46,7 +47,7 @@ export class NSRouterLink {
4647

4748
constructor(private _router: Router, private _location: Location) { }
4849

49-
// get isRouteActive(): boolean { return this._router.isRouteActive(this._navigationInstruction); }
50+
get isRouteActive(): boolean { return this._router.isRouteActive(this._navigationInstruction); }
5051

5152
set params(changes: any[]) {
5253
this._routeParams = changes;

0 commit comments

Comments
 (0)