NativeScript TabView 导航

NativeScript TabView Navigation

我正在创建一个从 NativeScript TabView 模板应用程序 (https://github.com/NativeScript/template-tab-navigation-ng) 开始的应用程序,但我不知道如何以编程方式导航到来自 AppComponent 的页面路由器出口中的页面。示例:

export class AppComponent{

    constructor(private router: RouterExtensions, private currentRoute: ActivatedRoute) {
        // Use the component constructor to inject providers.
    }

    getIconSource(icon: string): string {
        const iconPrefix = isAndroid ? "res://" : "res://tabIcons/";
        return iconPrefix + icon;
    }

    navigateToPage(): void {
        this.router.navigate(['../page'], { relativeTo: this.currentRoute });
    }
}

这在 page-router-outlet 内的页面内工作正常,但是当我从 AppComponent 调用它时,我收到如下控制台错误:

Cannot match any routes. URL Segment: 'page'

我的实际代码在这里:https://github.com/rchisholm/saint_stan

我实际的完整错误在这里,来自调试控制台:

Unhandled Promise rejection: Cannot match any routes. URL Segment: 'novena-day/1' ; Zone: <root> ; Task: Promise.then ; Value: Error: Cannot match any routes. URL Segment: 'novena-day/1' Error: Cannot match any routes. URL Segment: 'novena-day/1'

我尝试的导航是在 AppComponent 的 OnInit 中的 LocalNotifications.addOnMessageReceivedCallback 内。

这看起来应该很简单。我对此有点陌生,所以任何帮助将不胜感激。

我正在使用最新版本的 NativeScript、TypeScript 和 Angular。

谢谢!

这就是您导航到某个 TabView 选项卡的方式。您的出口必须在 app.routing.ts 文件中设置。

private navigateToFoo() {
    this.routerExtensions.navigate([
        '/YourTabRouting', { outlets: { fooOutlet: ['foo'] } }
    ])
}