Nativescript Angular 路由器 3.0.0-alpha.7 - 导航失败
Nativescript Angular router 3.0.0-alpha.7 - Navigation failure
此项目示例中展示的问题:https://github.com/rrcoolp/test-router-app/
导航失败:我创建了这个测试项目来提出 NATIVESCRIPT ANGULAR 2 (RC3) Nativescript with router 3.0.0-alpha.7
的问题
问题很简单,第一次导航后导航到另一个页面失败。要查看实际问题,请执行以下步骤:
点击任何按钮(GOTO PAGE 1 或 GOTO PAGE 2):首先点击相应的页面并呈现其内容
对任一按钮(包括 CHILD 组件)的任何后续点击都会在导航中失败
任何帮助将不胜感激...
这是我的 APP_COMPONENT 文件的示例:
import {Component, OnInit, ChangeDetectorRef} from "@angular/core";
import {NS_ROUTER_DIRECTIVES} from "nativescript-angular/router";
import {ROUTER_DIRECTIVES, Router} from '@angular/router';
import {APP_ROUTER_PROVIDERS} from "./app.routes";
import {Location, LocationStrategy} from "@angular/common";
import {app_globals} from "./utils/globals";
@Component({
selector: "main",
directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
providers: [APP_ROUTER_PROVIDERS],
templateUrl: "masterpage.html"
})
export class AppComponent implements OnInit {
showBackButton: boolean = false;
history: any = [];
pushState: any;
constructor(public _router: Router, private _changeDetectionRef: ChangeDetectorRef, private _Location: Location, private _LocationStrategy: LocationStrategy, private _app_globals: app_globals) {
this._changeDetectionRef = _changeDetectionRef;
this._LocationStrategy = _LocationStrategy;
}
ngOnInit() {
this._app_globals.navigateTo$.subscribe(val => {
console.log("SUBSCRIBED NAVIATE TO:" + val);
this.navigateTo(val);
});
}
goBack() {
this._LocationStrategy.back();
}
navigateTo(page) {
console.log("GotoTestPage"+page);
this._router.navigate(["testpage"+page, "PAGE"+page]).then(() => {
alert("Route Completed but see content didn't change to PAGE"+page);
});
}
GotoTestPage2() {
this.navigateTo("2");
}
GotoTestPage1() {
this.navigateTo("1");
}
}
通过在导航方法中指定绝对路径使其工作(添加前导“/”):
this._router.navigate(["/testpage"+page, "PAGE"+page]).then(() => { ... });
此项目示例中展示的问题:https://github.com/rrcoolp/test-router-app/
导航失败:我创建了这个测试项目来提出 NATIVESCRIPT ANGULAR 2 (RC3) Nativescript with router 3.0.0-alpha.7
的问题问题很简单,第一次导航后导航到另一个页面失败。要查看实际问题,请执行以下步骤:
点击任何按钮(GOTO PAGE 1 或 GOTO PAGE 2):首先点击相应的页面并呈现其内容
对任一按钮(包括 CHILD 组件)的任何后续点击都会在导航中失败
任何帮助将不胜感激...
这是我的 APP_COMPONENT 文件的示例:
import {Component, OnInit, ChangeDetectorRef} from "@angular/core";
import {NS_ROUTER_DIRECTIVES} from "nativescript-angular/router";
import {ROUTER_DIRECTIVES, Router} from '@angular/router';
import {APP_ROUTER_PROVIDERS} from "./app.routes";
import {Location, LocationStrategy} from "@angular/common";
import {app_globals} from "./utils/globals";
@Component({
selector: "main",
directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
providers: [APP_ROUTER_PROVIDERS],
templateUrl: "masterpage.html"
})
export class AppComponent implements OnInit {
showBackButton: boolean = false;
history: any = [];
pushState: any;
constructor(public _router: Router, private _changeDetectionRef: ChangeDetectorRef, private _Location: Location, private _LocationStrategy: LocationStrategy, private _app_globals: app_globals) {
this._changeDetectionRef = _changeDetectionRef;
this._LocationStrategy = _LocationStrategy;
}
ngOnInit() {
this._app_globals.navigateTo$.subscribe(val => {
console.log("SUBSCRIBED NAVIATE TO:" + val);
this.navigateTo(val);
});
}
goBack() {
this._LocationStrategy.back();
}
navigateTo(page) {
console.log("GotoTestPage"+page);
this._router.navigate(["testpage"+page, "PAGE"+page]).then(() => {
alert("Route Completed but see content didn't change to PAGE"+page);
});
}
GotoTestPage2() {
this.navigateTo("2");
}
GotoTestPage1() {
this.navigateTo("1");
}
}
通过在导航方法中指定绝对路径使其工作(添加前导“/”):
this._router.navigate(["/testpage"+page, "PAGE"+page]).then(() => { ... });