Angular导航上下文

Angular导航上下文

本文介绍了NativeScript + Angular导航上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在列表和详细信息页面之间导航.由于我已经获取了列表组件中的所有内容,因此我想将JSON传递给详细信息页面,以便我已经拥有呈现该组件所需的一切.

i'm trying to navigate between a list to a details page. Since i've already fetched everything in my list component i'd like to pass the JSON to the details page so that i've already everything I need to render the component.

我尝试了很多事情

this._router.navigate(['details', JSON.stringify(item)]) // seems to truncate the JSON
this._router.navigate(['details', item]) // raises an  Cannot match any routes

然后我尝试从路由定义中删除:item url参数并试图使用允许使用的queryParams参数,但是我无法在DetailsPage中读取它.

Then i tried to remove the :item url parameter from the route definitionand was trying to use the queryParams parameter which is allowed but i'm unable to read it in the DetailsPage.

推荐答案

这绝对不是该问题的答案,因为它不允许您发送完整的对象,但是如果您只需要向其中发送一些小参数,另一个页面",则可以使用查询参数来完成.

This is definitely not an answer to this question because it does not allow you to send a full object, but in case you need to send just some small parameters to another "page", you can accomplish that using query parameters.

this.routerExtensions.navigate(["/chats"], {
    replaceUrl: false,
    queryParams: {
        name: 'Some Name',
        id: 'some-id'
    }
});

您可以像在另一页上那样访问它们:

You can access them on the other page just like that:

import { ActivatedRoute } from "@angular/router";
[...]

constructor(private route: ActivatedRoute) {}

[...]
if (this.route.snapshot.queryParams) {
    const query = this.route.snapshot.queryParams

    console.log(`name: ${query['name']}`)
    console.log(`id: ${query['id']}`)
}

这篇关于NativeScript + Angular导航上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 06:53