@@ -278,7 +278,11 @@ export class Router<Renderable> extends EventTarget {
278278
279279 // Update outlet with the result
280280 this . #outlet = result ;
281- this . #location = location ;
281+ // Only update location for GET requests (navigation)
282+ // For non-GET requests (mutations), keep the current location
283+ if ( ! submission ) {
284+ this . #location = location ;
285+ }
282286
283287 // Set navigating to idle
284288 this . #navigating = {
@@ -541,12 +545,15 @@ export class Router<Renderable> extends EventTarget {
541545 */
542546 async navigate ( to : To , options : NavigateOptions = { } ) : Promise < void > {
543547 const pathname = this . #resolveTo( to ) ;
548+ const currentPath = window . location . pathname + window . location . search + window . location . hash ;
544549
545- // Update history
546- if ( options . replace ) {
547- window . history . replaceState ( { } , "" , pathname ) ;
548- } else {
549- window . history . pushState ( { } , "" , pathname ) ;
550+ // Update history only if the path is different
551+ if ( pathname !== currentPath ) {
552+ if ( options . replace ) {
553+ window . history . replaceState ( { } , "" , pathname ) ;
554+ } else {
555+ window . history . pushState ( { } , "" , pathname ) ;
556+ }
550557 }
551558
552559 // Perform navigation
@@ -622,8 +629,9 @@ export class Router<Renderable> extends EventTarget {
622629 formData = undefined ;
623630 }
624631
625- // Update history if this is a navigation
626- if ( options . navigate !== false ) {
632+ // Update history only for GET requests
633+ // Non-GET requests (POST, PUT, DELETE, etc.) should not change the URL or add history entries
634+ if ( options . navigate !== false && formMethod === "GET" ) {
627635 if ( options . replace ) {
628636 window . history . replaceState ( { } , "" , formAction ) ;
629637 } else {
0 commit comments