I am building the fragment string in javascript from a form and setting with window.location.hash. If a user leaves a form input blank the resulting URL can be
example.com/#search/cars//blue//mazda
Note the //
If say the price was entered it would be
example.com/#search/cars/20000/blue//mazda
Now this works fine. Is it bad practice?
I think that
pushStateand the other History API methods are so nascent that standards haven’t yet evolved. As opens a recent W3 work on Repurposing the Hash Sign for the New Web:It might violate normal behavior to use double slashes in the pathname but the hash fragment can be any arbitrary string. Do a
typeofand you’ll see it’s just a normal string. It’s not standard and therefore might alienate the typical user experience. Code wise, however, I think you can feel free to you double slashes, triple slashes, or anything else.One thing to keep in mind is that escaped characters are decoded when read from the
window.location.hashproperty.