-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathrouter-extensions.ts
80 lines (69 loc) · 2.04 KB
/
router-extensions.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
74
75
76
77
78
79
80
import {Component} from "@angular/core";
import {nativeScriptBootstrap} from 'nativescript-angular/application';
import {NS_ROUTER_DIRECTIVES } from 'nativescript-angular/router';
import {nsProvideRouter} from 'nativescript-angular/router';
import {RouterConfig} from '@angular/router';
import { RouterExtensions } from 'nativescript-angular/router';
@Component({
// ...
// >> (hide)
selector: "router-extensions-import",
directives: [NS_ROUTER_DIRECTIVES],
templateUrl: 'snippets/navigation/router-extensions.html'
// << (hide)
})
export class MyComponent {
constructor(private routerExtensions: RouterExtensions) { }
// >> router-clear-history-code
login() {
// app logic here ...
this.routerExtensions.navigate(["/main"], { clearHistory: true });
}
// << router-clear-history-code
// >> router-back
public goBack() {
this.routerExtensions.back();
}
// << router-back
// >> router-page-back
public goBackPage() {
this.routerExtensions.backToPreviousPage();
}
// << router-page-back
// >> router-page-transition-code
flipToNextPage() {
this.routerExtensions.navigate(["/main"], {
transition: {
name: "flip",
duration: 2000,
curve: "linear"
}
});
}
// << router-page-transition-code
}
// >> router-extensions-import
@Component({
// ...
// >> (hide)
selector: 'component',
template: `<StackLayout><Label text="Main Page"></Label></StackLayout>`
// << (hide)
})
export class MainComponent {
constructor(private routerExtensions: RouterExtensions) {
// ...
}
}
// << router-extensions-import
@Component({
selector: 'application',
directives: [NS_ROUTER_DIRECTIVES],
template: "<page-router-outlet></page-router-outlet>"
})
export class App { }
const routes: RouterConfig = [
{ path: "", component: MyComponent },
{ path: "main", component: MainComponent },
];
export const providers = nsProvideRouter(routes, {});