Skip to content

Commit 895845d

Browse files
author
Alexander Vakrilov
authored
Merge pull request #373 from NativeScript/nav-extensions-snippets
Navigation Extensions snippets
2 parents 9785e95 + 4dc355b commit 895845d

File tree

4 files changed

+110
-21
lines changed

4 files changed

+110
-21
lines changed

ng-sample/app/examples/router/router-outlet-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, OnInit, OnDestroy } from "@angular/core";
22
import { RouterConfig, ActivatedRoute, ROUTER_DIRECTIVES } from '@angular/router';
3-
import { NS_ROUTER_DIRECTIVES, nsProvideRouter} from "nativescript-angular/router"
3+
import { NS_ROUTER_DIRECTIVES, nsProvideRouter} from "nativescript-angular/router";
44

55
@Component({
66
selector: "first",

tests/app/snippets/navigation/navigation-common.ts

+1-20
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,4 @@ export class FirstComponent { }
2323
</StackLayout>`
2424
})
2525
export class SecondComponent { }
26-
// << router-content-components
27-
28-
29-
// >> router-location-back
30-
import {Location} from '@angular/common';
31-
32-
@Component({
33-
// ...
34-
// >> (hide)
35-
template: '', selector:"go-back"
36-
// << (hide)
37-
})
38-
export class MyComponent {
39-
constructor(private location: Location) { }
40-
41-
public goBack() {
42-
this.location.back();
43-
}
44-
}
45-
// << router-location-back
26+
// << router-content-components
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<StackLayout>
2+
<Label text="Second component" class="title"></Label>
3+
<!-- >> router-clear-history-link -->
4+
<Button text="login" [nsRouterLink]="['/main']" clearHistory="true"></Button>
5+
<!-- << router-clear-history-link -->
6+
7+
<!-- >> router-page-transition-link -->
8+
<Button text="flip to next" [nsRouterLink]="['/main']" pageTransition="flip"></Button>
9+
<Button text="no transition" [nsRouterLink]="['/main']" pageTransition="none"></Button>
10+
<!-- << router-page-transition-link -->
11+
12+
13+
<!-- >> router-clear-history-code-->
14+
<Button text="login" (tap)="login()"></Button>
15+
<!-- << router-clear-history-code -->
16+
17+
<!-- >> router-back -->
18+
<Button text="< BACK" (tap)="goBack()"></Button>
19+
<!-- << router-back -->
20+
21+
<!-- >> router-page-back -->
22+
<Button text="<< BACK" (tap)="goBackPage()"></Button>
23+
<!-- << router-page-back -->
24+
25+
<!-- >> router-page-transition-code -->
26+
<Button text="flip to next" (tap)="flipToNextPage()"></Button>
27+
<!-- << router-page-transition-code -->
28+
</StackLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import {Component} from "@angular/core";
2+
import {nativeScriptBootstrap} from 'nativescript-angular/application';
3+
import {NS_ROUTER_DIRECTIVES } from 'nativescript-angular/router';
4+
import {nsProvideRouter} from 'nativescript-angular/router';
5+
import {RouterConfig} from '@angular/router';
6+
7+
8+
import { RouterExtensions } from 'nativescript-angular/router';
9+
10+
@Component({
11+
// ...
12+
// >> (hide)
13+
selector: "router-extensions-import",
14+
directives: [NS_ROUTER_DIRECTIVES],
15+
templateUrl: 'snippets/navigation/router-extensions.html'
16+
// << (hide)
17+
})
18+
export class MyComponent {
19+
constructor(private routerExtensions: RouterExtensions) { }
20+
21+
// >> router-clear-history-code
22+
login() {
23+
// app logic here ...
24+
this.routerExtensions.navigate(["/main"], { clearHistory: true });
25+
}
26+
// << router-clear-history-code
27+
28+
// >> router-back
29+
public goBack() {
30+
this.routerExtensions.back();
31+
}
32+
// << router-back
33+
34+
// >> router-page-back
35+
public goBackPage() {
36+
this.routerExtensions.backToPreviousPage();
37+
}
38+
// << router-page-back
39+
40+
// >> router-page-transition-code
41+
flipToNextPage() {
42+
this.routerExtensions.navigate(["/main"], {
43+
transition: {
44+
name: "flip",
45+
duration: 2000,
46+
curve: "linear"
47+
}
48+
});
49+
}
50+
// << router-page-transition-code
51+
}
52+
53+
// >> router-extensions-import
54+
@Component({
55+
// ...
56+
// >> (hide)
57+
selector: 'component',
58+
template: `<StackLayout><Label text="Main Page"></Label></StackLayout>`
59+
// << (hide)
60+
})
61+
export class MainComponent {
62+
constructor(private routerExtensions: RouterExtensions) {
63+
// ...
64+
}
65+
}
66+
// << router-extensions-import
67+
68+
@Component({
69+
selector: 'application',
70+
directives: [NS_ROUTER_DIRECTIVES],
71+
template: "<page-router-outlet></page-router-outlet>"
72+
})
73+
export class App { }
74+
75+
const routes: RouterConfig = [
76+
{ path: "", component: MyComponent },
77+
{ path: "main", component: MainComponent },
78+
];
79+
80+
export const providers = nsProvideRouter(routes, {});

0 commit comments

Comments
 (0)