NativeScript TabView导航

时间:2018-09-12 01:41:08

标签: angular typescript navigation nativescript tabview

我正在从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的最新版本。

谢谢!

1 个答案:

答案 0 :(得分:2)

这是您导航到某些TabView选项卡的方式。您的商店必须在app.routing.ts文件中设置。

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