1
+ import { Component } from '@angular/core' ;
2
+ import { RouteConfig , ROUTER_PROVIDERS , ROUTER_DIRECTIVES , ComponentInstruction , Router , RouteParams , RouteData } from '@angular/router-deprecated' ;
3
+ import { NS_ROUTER_DIRECTIVES , NS_ROUTER_PROVIDERS } from "../../nativescript-angular/router/ns-router" ;
4
+ import { isBlank } from '@angular/core/src/facade/lang' ;
5
+
6
+ @Component ( {
7
+ selector : 'login-page' ,
8
+ directives : [ NS_ROUTER_DIRECTIVES ] ,
9
+ template : `
10
+ <StackLayout>
11
+ <StackLayout orientation='horizontal'>
12
+ <Label text="user: "></Label>
13
+ <TextField text="user"></TextField>
14
+ </StackLayout>
15
+ <StackLayout orientation='horizontal'>
16
+ <Label text="pass: "></Label>
17
+ <TextField text="pass"></TextField>
18
+ </StackLayout>
19
+ <Button text='Login' (tap)="onLoginTap()"></Button>
20
+ </StackLayout>
21
+ `
22
+ } )
23
+ export class LoginPage {
24
+ private router : Router ;
25
+ constructor ( private _router : Router ) {
26
+ this . router = _router ;
27
+ }
28
+ onLoginTap ( args ) {
29
+ this . router . navigate ( [ "Main" , { "success" : true } ] ) ;
30
+ }
31
+ }
32
+
33
+ @Component ( {
34
+ selector : 'main' ,
35
+ directives : [ NS_ROUTER_DIRECTIVES ] ,
36
+ template : `
37
+ <TextField text="Main Content"></TextField>
38
+ `
39
+ } )
40
+ export class MainComponent {
41
+ private getParamOrData ( key : string , params : RouteParams , data : RouteData ) {
42
+ let result = params . get ( key ) ;
43
+ if ( ! isBlank ( result ) ) {
44
+ return result ;
45
+ } else {
46
+ return data . get ( key ) ;
47
+ }
48
+ }
49
+
50
+ constructor ( params : RouteParams , private _router : Router , private _data : RouteData ) {
51
+ let success = this . getParamOrData ( "success" , params , _data ) ;
52
+ if ( ! success ) {
53
+ _router . navigate ( [ "Login" ] ) ;
54
+ }
55
+ console . log ( "params: " + params ) ;
56
+ }
57
+ }
58
+
59
+ @Component ( {
60
+ selector : 'login-test' ,
61
+ directives : [ NS_ROUTER_DIRECTIVES ] ,
62
+ template : `<page-router-outlet></page-router-outlet>`
63
+ } )
64
+ @RouteConfig ( [
65
+ { path : '/login' , component : LoginPage , name : 'Login' } ,
66
+ { path : '/main' , component : MainComponent , name : 'Main' , data : { "success" : false } , useAsDefault : true } ,
67
+ ] )
68
+ export class LoginTest {
69
+
70
+ }
0 commit comments