diff --git a/ng-sample/app/app.ts b/ng-sample/app/app.ts index 1310bf8e3..c4d3f0090 100644 --- a/ng-sample/app/app.ts +++ b/ng-sample/app/app.ts @@ -11,9 +11,9 @@ import { NS_ROUTER_PROVIDERS, routerTraceCategory } from "./nativescript-angular import { rendererTraceCategory } from "./nativescript-angular/renderer"; import trace = require("trace"); -// trace.setCategories(routerTraceCategory + ", " + rendererTraceCategory); +//trace.setCategories(routerTraceCategory + ", " + rendererTraceCategory); // trace.setCategories(rendererTraceCategory); -// trace.setCategories(routerTraceCategory); +trace.setCategories(routerTraceCategory); trace.enable(); import {RendererTest} from './examples/renderer-test'; @@ -27,8 +27,9 @@ import {ActionBarTest} from "./examples/action-bar/action-bar-test"; import {ModalTest} from "./examples/modal/modal-test"; import {PlatfromDirectivesTest} from "./examples/platform-directives/platform-directives-test"; import {RouterOutletTest} from "./examples/navigation/router-outlet-test"; +import {LoginTest} from "./examples/navigation/login-test"; -nativeScriptBootstrap(RendererTest); +//nativeScriptBootstrap(RendererTest); //nativeScriptBootstrap(TabViewTest); //nativeScriptBootstrap(Benchmark); //nativeScriptBootstrap(ListTest); @@ -40,3 +41,4 @@ nativeScriptBootstrap(RendererTest); //nativeScriptBootstrap(ModalTest); //nativeScriptBootstrap(PlatfromDirectivesTest); //nativeScriptBootstrap(RouterOutletTest, [NS_ROUTER_PROVIDERS]); +nativeScriptBootstrap(LoginTest, [NS_ROUTER_PROVIDERS]); \ No newline at end of file diff --git a/ng-sample/app/examples/navigation/login-test.ts b/ng-sample/app/examples/navigation/login-test.ts new file mode 100644 index 000000000..cec2d17ff --- /dev/null +++ b/ng-sample/app/examples/navigation/login-test.ts @@ -0,0 +1,70 @@ +import {Component} from '@angular/core'; +import {RouteConfig, ROUTER_PROVIDERS, ROUTER_DIRECTIVES, ComponentInstruction, Router, RouteParams, RouteData} from '@angular/router-deprecated'; +import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "../../nativescript-angular/router/ns-router"; +import {isBlank} from '@angular/core/src/facade/lang'; + +@Component({ + selector: 'login-page', + directives: [NS_ROUTER_DIRECTIVES], + template: ` + + + + + + + + + + + + ` +}) +export class LoginPage { + private router: Router; + constructor(private _router: Router){ + this.router = _router; + } + onLoginTap(args) { + this.router.navigate(["Main", { "success" : true }]); + } +} + +@Component({ + selector: 'main', + directives: [NS_ROUTER_DIRECTIVES], + template: ` + + ` +}) +export class MainComponent { + private getParamOrData(key: string, params: RouteParams, data: RouteData) { + let result = params.get(key); + if (!isBlank(result)) { + return result; + } else { + return data.get(key); + } + } + + constructor(params: RouteParams, private _router: Router, private _data: RouteData) { + let success = this.getParamOrData("success", params, _data); + if (!success) { + _router.navigate(["Login"]); + } + console.log("params: " + params); + } +} + +@Component({ + selector: 'login-test', + directives: [NS_ROUTER_DIRECTIVES], + template: `` +}) +@RouteConfig([ + { path: '/login', component: LoginPage, name: 'Login' }, + { path: '/main', component: MainComponent, name: 'Main', data: {"success": false}, useAsDefault: true }, +]) +export class LoginTest { + +} \ No newline at end of file diff --git a/src/nativescript-angular/router/ns-router-link.ts b/src/nativescript-angular/router/ns-router-link.ts index 6373141af..e0bd5dd37 100644 --- a/src/nativescript-angular/router/ns-router-link.ts +++ b/src/nativescript-angular/router/ns-router-link.ts @@ -1,7 +1,6 @@ import {Directive, Input} from '@angular/core'; import {isString} from '@angular/core/src/facade/lang'; import {Router, Instruction} from '@angular/router-deprecated'; -import {Location} from '@angular/common'; import { log } from "./common"; /** @@ -46,7 +45,7 @@ export class NSRouterLink { // the instruction passed to the router to navigate private _navigationInstruction: Instruction; - constructor(private _router: Router, private _location: Location) { } + constructor(private _router: Router) { } get isRouteActive(): boolean { return this._router.isRouteActive(this._navigationInstruction); }