-
7 Nov 2012 3:35 AM #1
Unanswered: Save current route url to localStorage
Unanswered: Save current route url to localStorage
Hello,
since the only way to restore the state of a web app added to the iOS homescreen is by using routing, I'm searching for a way to store the current route's hash url to localStorage, so I can load it the next time the user opens the app.
The easiest way to store the url is:
However, I need to save this url everytime the app launches a "redirectTo(...)". I didn't find a specific event or a way to intercept it. How do you do it?Code:localStorage.setItem('url', location.hash.substr(1));
Thanks
-
7 Nov 2012 4:13 AM #2
Code:Ext.define('controller',{ config:{ before:{ showUser:'storeUrl' }, routes:{ 'user/:id': 'showUser' } }, storeUrl:function(action){ localStorage.setItem('url', location.hash.substr(1)); action.resume(); } })I write English by translator.
-
7 Nov 2012 4:20 AM #3
Thanks for your reply.
That means that I need to add a "before" config for every action. There's a clean way to launch it before ANY action?
Here's my dirty method:
Code:if (Ext.feature.has.History) { window.addEventListener('hashchange', Ext.bind(saveUrl, this)); } function saveUrl(location){ var hash; if (location.hash) { // object hash = location.hash; } else if (location.newURL) { // hashchange event var anchor = document.createElement('a'); anchor.href = location.newURL; hash = anchor.hash; delete anchor; } localStorage.setItem('url', hash.substr(1)); }


Reply With Quote