-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathrouter-outlet-test.ts
73 lines (63 loc) · 2.04 KB
/
router-outlet-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Component, OnInit, OnDestroy } from "@angular/core";
import { RouterConfig, ActivatedRoute, ROUTER_DIRECTIVES } from '@angular/router';
import { NS_ROUTER_DIRECTIVES, nsProvideRouter} from "nativescript-angular/router";
@Component({
selector: "first",
styleUrls: ["examples/router/styles.css"],
template: `
<StackLayout>
<Label text="First component" class="title"></Label>
</StackLayout>`
})
class FirstComponent implements OnInit, OnDestroy {
ngOnInit() {
console.log("FirstComponent - ngOnInit()");
}
ngOnDestroy() {
console.log("FirstComponent - ngOnDestroy()");
}
}
@Component({
selector: "second",
styleUrls: ["examples/router/styles.css"],
template: `
<StackLayout>
<Label [text]="'Second component: ' + (id | async)" class="title"></Label>
</StackLayout>`
})
class SecondComponent implements OnInit, OnDestroy {
id;
constructor(route: ActivatedRoute) {
this.id = route.params.map(r => r["id"]);
}
ngOnInit() {
console.log("SecondComponent - ngOnInit()");
}
ngOnDestroy() {
console.log("SecondComponent - ngOnDestroy()");
}
}
@Component({
selector: 'navigation-test',
directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
styleUrls: ["examples/router/styles.css"],
template: `
<StackLayout>
<StackLayout class="nav">
<Button text="First" nsRouterLink="/"></Button>
<Button text="Second(1)" nsRouterLink="/second/1"></Button> <!-- Both work -->
<Button text="Second(2)" [nsRouterLink]="['/second', '2' ]"></Button> <!-- Both work -->
</StackLayout>
<router-outlet></router-outlet>
</StackLayout>
`
})
export class RouterOutletAppComponent {
}
const routes: RouterConfig = [
{ path: "", component: FirstComponent},
{ path: "second/:id", component: SecondComponent },
];
export const RouterOutletRouterProviders = [
nsProvideRouter(routes, { enableTracing: false })
];