vakata / jstree

jquery tree plugin
http://jstree.com
MIT License
5.15k stars 1.38k forks source link

Keep state on refresh but clear on navigation between pages #2623

Closed zoaina closed 1 year ago

zoaina commented 2 years ago

I can clear state on every loading event using the code below. Does exists a way to clear state only when user navigate between pages but keep state on page reload ?

$('jstree-elt').on('loading.jstree', function (e, data) {
    localStorage.removeItem('jstree');
});
vakata commented 1 year ago

This is custom logic you will have to do on your own - you have the ability to clear the cache (even with the included config options - .filter for example: https://www.jstree.com/api/#/?q=.state&f=$.jstree.defaults.state.filter). Whether you do that can depend on a variable you set, for example - localStorage.setItem('last_page', window.location.toString()), and then compare with the current location - that way you know if this is the same page or not. You can also set the state key to a hash of the current location - that way each page will have its own state.