You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varparseQueryString=function(input){// similar to PHP $_GET[key]// return array of values if key is repeated in query stringletqueryObject={};constre=/([^?&=]+)(?:=([^&]+))?/g;letmatch;while(match=re.exec(input)){const[k,v]=[decodeURIComponent(match[1]),// empty value = true(decodeURIComponent(match[2])||true)];if(kinqueryObject){if(Array.isArray(queryObject[k])){queryObject[k].push(v);}else{queryObject[k]=[queryObject[k],v];}}else{queryObject[k]=v;}}returnqueryObject;};// keys shared between state and fragment query string// key "code" is always sharedconstfragmentKeys=["input"];vargetStateDiffFromFragment=function(){// fragment string format: key=val&key2=val2/codeString// val, val2, ... must be encoded with encodeURIComponent// codeString can be encoded with encodeURI// which is more compact than encodeURIComponentconstidxCode=document.location.hash.indexOf("/");constquery=parseQueryString(document.location.hash.substring(1,idxCode));letstateDiff=Object.keys(query).reduce((acc,key)=>{if(fragmentKeys.includes(key)){acc[key]=query[key];}returnacc;},{});constcode=decodeURI(document.location.hash.substring(idxCode+1));if(code){stateDiff.code=code;}returnstateDiff;};varsetFragmentFromState=function(state){document.location.hash=fragmentKeys.reduce((acc,key)=>{if(state[key]){acc.push(`${key}=${encodeURIComponent(state[key])}`)}returnacc;},[]).join("&")+"/"+encodeURI(state.code);};
javascript says document.location.hash, the official name is fragment identifier
limitation: old browsers limit URL length
license is creative-commons-zero, so feel free to steal my code
ps: can you make /gh-pages public? (including jsx files)
The text was updated successfully, but these errors were encountered:
please include this feature on the demo page, so we can link to demo code
sample implementation:
javascript says
document.location.hash
, the official name is fragment identifierlimitation: old browsers limit URL length
license is creative-commons-zero, so feel free to steal my code
ps: can you make
/gh-pages
public? (including jsx files)The text was updated successfully, but these errors were encountered: