【问题标题】:NativeScript TabView NavigationNativeScript TabView 导航
【发布时间】:2019-02-16 13:42:18
【问题描述】:

我正在从 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。

谢谢!

【问题讨论】:

    标签: angular typescript navigation nativescript tabview


    【解决方案1】:

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

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

    【讨论】:

    • 如何在 app-routing.module.ts 中设置网点?我的路径是这样设置的:{ path: "pageOne", component: PageOneComponent, outlet: "tabOne" }
    • (“pageOne”是我的出口“tabOne”中的一个页面)
    • 感谢您的回答@mrisek,您的回答很有帮助。
    • 感谢@RussellChisholm,如果您觉得答案有用,别忘了点赞。
    猜你喜欢
    • 1970-01-01
    • 2019-06-15
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 2018-05-15
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多