Some online articles says, that there is no standard for querystring
and hash
in URL, but we are following what has continued to happen. So, my question is what should be a better way of having both querystring and hash in same URL.
The problem I think is, if hash follows querystring, it can become a value to some querystring data and if querystring follows hash, the whole querystring may become a hask. So, what order should I follow?
Some online articles says, that there is no standard for querystring and hash in URL
Either they are wrong or you are misinterpreting them.
The query string must appear before the fragment identifier (which you call the hash).
The specification shows the format of a URI:
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
It clearly shows the fragment appearing after the query.
if hash follows querystring, it can become a value to some querystring data
It can't. The #
is a special character that indicates the start of the fragment. To include one in query string data it needs to be escaped as %23
.
This is something I tried in JavaScript:
window.location="alpha#abc?def=34";
console.log(window.location);
The result was:
Location {
hash: "#abc?def=34",
search: "",
...otherData
}
And, then:
window.location="alpha?abc=34#def";
console.log(window.location);
The result was:
Location {
hash: "#def",
search: "?abc=34",
...otherData
}
Clearly, JavaScript does not distinguish anything after # symbol, while querystring before hash works fine.
So, we should use querystring first and then hash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With