JSFiddle - React, Tailwind, and code Playground
HTML
<a href="/page/file.html?get#hash">link1</a>
<a href="/page/file.html">link2</a>
<a href="/page/">link3</a>
<a href="/page">link4</a>
<a href="">empty</a>
<a>undefined</a>
JavaScript
$(function(){
$(document).on('click','a',function()
{
var pathname = this.pathname;
var search = this.search;
var hash = this.hash;
if(pathname === undefined)
pathname = '';
pathname = pathname.split('/');
if(pathname[pathname.length-1].match(/\./) != null)
pathname.splice(-1,1);
pathname = pathname.join('/');
history.pushState(null, null, pathname+search+hash);
alert(pathname+search+hash);
return false;
});
});