If your application is not deployed at the root (such as with a virtual directory, or just in a deeper hierarchy) then you'll end up screwing up the URL if you do history.pushState({}, '/newpath');
There's a couple alternatives :
1) Get your root path in a javascript variable that you can just prepend the URL to it. In this example window.ViewModel.rootPath
is just an arbitrary place - just modify this for however you want to store global variables.
You will have to set the rootPath
in script (example here for .NET).
<script>
window.ViewModel.rootPath = "@Request.ApplicationPath";
</script>
history.pushState({}, window.ViewModel.rootPath + '/newpath');
2) Check if the URL ends with a /
and if it does you need to go up 1 directory level. Note: This approach requires you to know the 'parent' directory of what you're posting - in this case YourAccount
.
history.pushState({ mode: 'Club' }, '',
(window.location.href.endsWith('/') ? '../' : '') +
'YourAccount/ManageClub/' + id );
If the current URL is /preview/store/YourAccount
then this will become ../YourAccount/ManageClub/123
.
If the current URL is /preview/store/YourAccount/
then this will become YourAccount/ManageClub/123
.
These with both end up at the same URL.