[英]I can't seem to figure out how to manipulate the browser history
So what I am trying to do is change data based on the navigation of a user.所以我想做的是根据用户的导航更改数据。 I have 6 main category pages.
我有 6 个主要类别页面。 From those 6 main category pages, I have 12 sub categories that the user can select.
从这 6 个主要类别页面中,我有 12 个子类别可供用户选择。
Let's say the user selects category one.假设用户选择类别一。
So I can do the category one to sub-category 1 but how would I do it for lets says sub-category 1 to 2 and from 2 to 3...n times....?因此,我可以将类别 1 设为子类别 1,但是我将如何执行子类别 1 到 2 以及从 2 到 3 ...... n 次......? Each sub-category has to know which main category was last selected.
每个子类别都必须知道最后选择的是哪个主要类别。
I have looked at but can't seem to find a solution.我已经看过了,但似乎找不到解决方案。
window.location.hash
history.pushState("","","");
document.referrer
Typically this is a bad design and I understand that but I am limited to what I can do on the server side.通常这是一个糟糕的设计,我理解这一点,但我只能在服务器端做些什么。 So trying to develop a work around....
所以试图开发一个解决方法......
After trying to work with these and not getting the desired behavior, I was able to find the best solution through several hours of research.在尝试使用这些并没有获得所需的行为后,我能够通过几个小时的研究找到最佳解决方案。 The only alternative I could find for passing around data on the client side between pages.
我能找到的唯一替代方法是在页面之间的客户端传递数据。
window.location.hash
history.pushState("","","");
document.referrer
So lets say the user navigates to category1假设用户导航到 category1
You would set a session storage object您将设置会话存储对象
sessionStorage.setItem('last-category', "category1");
The user navigates sub-category 1. You can use this to get the session storage of an object and will show the last set operation for that object.用户导航子类别 1。您可以使用它来获取对象的会话存储并显示该对象的最后一次设置操作。
sessionStorage.getItem("last-category"); -> output category1
The user navigates sub-category 2用户导航子类别 2
sessionStorage.getItem("last-category"); -> output category1
The user navigates to category 2 You would set the session storage object again to show category2用户导航到类别 2 您将再次设置会话存储对象以显示类别 2
sessionStorage.setItem('last-category', "category2");
The user navigates to sub-category 1用户导航到子类别 1
sessionStorage.getItem("last-category"); -> output category2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.