@@ -433,6 +433,23 @@ return (function () {
433433 }
434434 }
435435
436+ function normalizePath ( path ) {
437+ try {
438+ var url = new URL ( path ) ;
439+ if ( url ) {
440+ path = url . pathname + url . search ;
441+ }
442+ // remove trailing slash, unless index page
443+ if ( ! path . match ( '^/$' ) ) {
444+ path = path . replace ( / \/ + $ / , '' ) ;
445+ }
446+ return path ;
447+ } catch ( e ) {
448+ // be kind to IE11, which doesn't support URL()
449+ return path ;
450+ }
451+ }
452+
436453 //==========================================================================================
437454 // public API
438455 //==========================================================================================
@@ -1301,7 +1318,7 @@ return (function () {
13011318 var verb , path ;
13021319 if ( elt . tagName === "A" ) {
13031320 verb = "get" ;
1304- path = getRawAttribute ( elt , ' href' ) ;
1321+ path = elt . href ; // DOM property gives the fully resolved href of a relative link
13051322 } else {
13061323 var rawAttribute = getRawAttribute ( elt , "method" ) ;
13071324 verb = rawAttribute ? rawAttribute . toLowerCase ( ) : "get" ;
@@ -2037,6 +2054,8 @@ return (function () {
20372054 return ;
20382055 }
20392056
2057+ url = normalizePath ( url ) ;
2058+
20402059 var historyCache = parseJSON ( localStorage . getItem ( "htmx-history-cache" ) ) || [ ] ;
20412060 for ( var i = 0 ; i < historyCache . length ; i ++ ) {
20422061 if ( historyCache [ i ] . url === url ) {
@@ -2066,6 +2085,8 @@ return (function () {
20662085 return null ;
20672086 }
20682087
2088+ url = normalizePath ( url ) ;
2089+
20692090 var historyCache = parseJSON ( localStorage . getItem ( "htmx-history-cache" ) ) || [ ] ;
20702091 for ( var i = 0 ; i < historyCache . length ; i ++ ) {
20712092 if ( historyCache [ i ] . url === url ) {
0 commit comments