問題展示在這個項目上例如:https://github.com/rrcoolp/test-router-app/Nativescript角路由器3.0.0-alpha.7 - 導航故障
導航失敗:我創建了這個測試項目提出的問題與NATIVESCRIPT ANGULAR 2(RC3)Nativescript與路由器3.0.0-alpha.7
問題很簡單,首次導航後導航到另一個頁面失敗。在行動中看到問題,請按照下列步驟操作:
點擊任何按鈕(GOTO PAGE 1頁轉到頁2):後先點擊相應頁面,它的內容呈現
任何後續點擊,任一按鈕(包括子組件)的失敗,在導航
任何幫助將不勝感激...
這裏是我的APP_COMP的樣本ONENT文件:
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({
\t selector: "main",
\t directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
\t providers: [APP_ROUTER_PROVIDERS],
\t templateUrl: "masterpage.html"
})
export class AppComponent implements OnInit {
\t showBackButton: boolean = false;
\t history: any = [];
\t pushState: any;
\t constructor(public _router: Router, private _changeDetectionRef: ChangeDetectorRef, private _Location: Location, private _LocationStrategy: LocationStrategy, private _app_globals: app_globals) {
\t \t this._changeDetectionRef = _changeDetectionRef;
\t \t this._LocationStrategy = _LocationStrategy;
\t }
\t ngOnInit() {
\t \t this._app_globals.navigateTo$.subscribe(val => {
\t \t \t console.log("SUBSCRIBED NAVIATE TO:" + val);
\t \t \t this.navigateTo(val);
\t \t });
\t }
\t goBack() {
\t \t this._LocationStrategy.back();
\t }
\t navigateTo(page) {
\t \t console.log("GotoTestPage"+page);
\t \t this._router.navigate(["testpage"+page, "PAGE"+page]).then(() => {
\t \t \t alert("Route Completed but see content didn't change to PAGE"+page);
\t \t \t
\t \t });
\t }
\t GotoTestPage2() {
\t \t this.navigateTo("2");
\t }
\t GotoTestPage1() {
\t \t this.navigateTo("1");
\t }
}
TNS運行Android – Rrcoolp
確保應用路由器提供商只定義一次。嘗試將這些提供程序僅移至引導程序方法。如果這不起作用,我可以稍後再看看。現在在一家咖啡館。 – Matthew
我還沒有嘗試過使用路由器插座,但是可以爲它添加一個基本路由嗎? router-outlet> https://github.com/NativeScript/nativescript-angular/blob/master/ng-sample/app/examples/router/router-outlet-test.ts#L67 –
Matthew