Skip to content

Navigation Extensions snippets #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ng-sample/app/examples/router/router-outlet-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit, OnDestroy } from "@angular/core";
import { RouterConfig, ActivatedRoute, ROUTER_DIRECTIVES } from '@angular/router';
import { NS_ROUTER_DIRECTIVES, nsProvideRouter} from "nativescript-angular/router"
import { NS_ROUTER_DIRECTIVES, nsProvideRouter} from "nativescript-angular/router";

@Component({
selector: "first",
Expand Down
21 changes: 1 addition & 20 deletions tests/app/snippets/navigation/navigation-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,4 @@ export class FirstComponent { }
</StackLayout>`
})
export class SecondComponent { }
// << router-content-components


// >> router-location-back
import {Location} from '@angular/common';

@Component({
// ...
// >> (hide)
template: '', selector:"go-back"
// << (hide)
})
export class MyComponent {
constructor(private location: Location) { }

public goBack() {
this.location.back();
}
}
// << router-location-back
// << router-content-components
28 changes: 28 additions & 0 deletions tests/app/snippets/navigation/router-extensions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<StackLayout>
<Label text="Second component" class="title"></Label>
<!-- >> router-clear-history-link -->
<Button text="login" [nsRouterLink]="['/main']" clearHistory="true"></Button>
<!-- << router-clear-history-link -->

<!-- >> router-page-transition-link -->
<Button text="flip to next" [nsRouterLink]="['/main']" pageTransition="flip"></Button>
<Button text="no transition" [nsRouterLink]="['/main']" pageTransition="none"></Button>
<!-- << router-page-transition-link -->


<!-- >> router-clear-history-code-->
<Button text="login" (tap)="login()"></Button>
<!-- << router-clear-history-code -->

<!-- >> router-back -->
<Button text="< BACK" (tap)="goBack()"></Button>
<!-- << router-back -->

<!-- >> router-page-back -->
<Button text="<< BACK" (tap)="goBackPage()"></Button>
<!-- << router-page-back -->

<!-- >> router-page-transition-code -->
<Button text="flip to next" (tap)="flipToNextPage()"></Button>
<!-- << router-page-transition-code -->
</StackLayout>
80 changes: 80 additions & 0 deletions tests/app/snippets/navigation/router-extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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, {});