最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Hide query params in the URL - Angular 5 - Stack Overflow

programmeradmin3浏览0评论

I am setting dynamic queryparams when navigating to a different route.

this.router.navigate(["/listing/list"], {
        queryParams: queryParams,
        skipLocationChange: true
      });
history.pushState(queryParams, "", "/listing/list");

And as I don't want the user to know query params I am using skipLocationChange and manually change the history using history.pushstate. Now I am able to receive the params when back clicked and returned back to the same page using browser back/forward buttons from popstate event. But parameter state is erased reloaded. Is there a way to persist query params while reloading the browser?

I am setting dynamic queryparams when navigating to a different route.

this.router.navigate(["/listing/list"], {
        queryParams: queryParams,
        skipLocationChange: true
      });
history.pushState(queryParams, "", "/listing/list");

And as I don't want the user to know query params I am using skipLocationChange and manually change the history using history.pushstate. Now I am able to receive the params when back clicked and returned back to the same page using browser back/forward buttons from popstate event. But parameter state is erased reloaded. Is there a way to persist query params while reloading the browser?

Share Improve this question asked Jan 29, 2018 at 14:49 Harish KrishnanHarish Krishnan 1,8214 gold badges18 silver badges26 bronze badges 6
  • The user can hit F12 and look in the network tab to see the parms. You can persist them in localStorage or sessionSstorage – mplungjan Commented Jan 29, 2018 at 14:52
  • Anything that you send to the client, the user can see if they know where to look. If you want something to be secret, don't send it. – Joe Clay Commented Jan 29, 2018 at 14:54
  • you can achieve this storing the data on a sharedService – CREM Commented Jan 29, 2018 at 14:58
  • if we reload shared service data will not be persisted right ? – Harish Krishnan Commented Jan 29, 2018 at 15:18
  • Data will be deleted but you can create an store data on your server to synchronize on this kind of situations. All this if you can't use local storage or Session Storage. – CREM Commented Jan 29, 2018 at 16:10
 |  Show 1 more ment

1 Answer 1

Reset to default 3

You can use LocalStorage or SessionStorage persist the data in the browser

  • sessionStorage if the browser will be closed the data will be gone.
  • LocalStorage the data will exist after browser closing and reopening, will never expire.

Caution with the Dev Tools you can explore the stored data, maybe you can use base64 or use a strong encryption algorithm for obfuscating the information.

发布评论

评论列表(0)

  1. 暂无评论