【发布时间】: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