Reputation: 2858
I'm developing some single page features and I'm using window.location.hash
to rebuild the page after a refresh.
Basically I have a simple menu like this:
<a href = "#user">User</a>
<a href = "#comment">Comment List</a>
When pressing on the Comment List link the Browser URL will become:
myapp.com/#comment
On this page there are Remove links which call some AJAX function to remove the comment:
<a href = "#remove" class = "rmv-comment" data-id = "${commentId}">Remove Comment</a>
When pressing the Remove Comment link the Browser URL will become:
myapp.com/#remove
This is not very helpful because now I cannot rebuild the old page on a refresh. (The #comment
hash isn't present therefore some default page will be displayed)
I'm looking for a way to build an URL like:
myapp.com/#comment/#remove
I tried appending different characters (like \
or ?
) to #comment
but no luck. Thanks in advance.
Upvotes: 0
Views: 971
Reputation:
In modern browsers you can only use one hash symbol
Instead of myapp.com/#comment/#remove
you can use something like this:
myapp.com/comment/remove
To change the url without reloading the page use window.history
object:
window.history.pushState("", "Title", "/remove");
window.history.pushState("", "Title", "/comment/remove");
Upvotes: 1