从Angular的详细信息页面导航回来后,维护搜索页面的状态 [英] Maintain state of Search page after navigating back from details page in Angular

查看:107
本文介绍了从Angular的详细信息页面导航回来后,维护搜索页面的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,我需要在用户通过单击链接导航到详细信息页面时维护搜索结果页面的状态(即保留搜索结果网格的排序和过滤值).在搜索结果网格中,然后再次导航回到搜索页面.我尝试使用CustomReuseStartegy,但遇到了2个问题:

I'm new to angular and I have a requirement to maintain the state of the search results page(i.e preserve the sort and filter values of the search results grid) when the user navigates to the details page by clicking on a link in search results grid and navigates back to the search page again. I tried using CustomReuseStartegy but I'm facing 2 issues:

  1. 当用户在详细信息页面中进行某些更改时,需要更新搜索结果.
  2. 页面分离后.它不再被附着. (当用户导航到其他页面(不同页面而不是详细信息页面)并返回搜索页面时,该页面不会重新加载.

如果有人能够提供关于使用路由重用策略或其他解决方案来满足我的要求的方式和时间重新连接组件的见解,那就太好了.

It would be great if someone can give insights on how and when to reattach the components using route reuse strategy or a different solution to handle my requirement.

推荐答案

如果需要维护组件(页面)之间的状态,则应使用服务.

If you need to maintain state between components (pages), you should use a service.

将数据存储在服务中的搜索"页面上,然后离开页面.当您返回搜索"页面时,请从服务中检索数据.

Store the data in the service on from the Search page, and leave the page. When you return to the Search page, retrieve the data from the service.

此外,如果需要,您可以将数据存储在localStorage或sessionStorage中.

Also, you can store data in localStorage or sessionStorage if that fits your requirement.

如果您使用的是Angular 1.x,请单击此处.

If you are using Angular 1.x click here.

对于Angular 2+,单击此处.

For Angular 2+ click here.

这篇关于从Angular的详细信息页面导航回来后,维护搜索页面的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆