如何从可观察到的pageRoute.activatedRoute获得ActiveRoute?

时间:2019-01-07 06:01:05

标签: nativescript angular2-nativescript

我需要将ActiveRoute传递给RouterExtensions.navigate()relativeTo参数。

this.routerExtensions.navigate(['page', {relativeTo: this.activeRoute}]);

我正在使用以下代码来观察可观察到的PageRoute.activatedRoute参数,但我无法弄清跟踪ActivateRoute可观察自身所需的操作。

constructor(private pageRoute: PageRoute, private routerExtensions: RouterExtensions) {
    this.pageRoute.activatedRoute.pipe(
        switchMap(activatedRoute => activatedRoute.params))
        .forEach((params) => {
            this.id = +params["id"];
        }
    );
}

我尝试使用Tap来跟踪activateRoute,但是它无法解析URL:

JS: ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'page'

tap的示例:

constructor(private pageRoute: PageRoute, private routerExtensions: RouterExtensions) {
    this.pageRoute.activatedRoute.pipe(
        tap(activatedRoute => this.activatedRoute = activatedRoute),
        switchMap(activatedRoute => activatedRoute.params))
        .forEach((params) => {
            this.id = +params["id"];
        }
    );
}

0 个答案:

没有答案