@@ -1181,7 +1181,7 @@ export class RouterCore<
11811181 return {
11821182 href : fullPath ,
11831183 publicHref : href ,
1184- url : url . href ,
1184+ url : url ,
11851185 pathname : decodePath ( pathname ) ,
11861186 searchStr,
11871187 search : replaceEqualDeep ( previousLocation ?. search , parsedSearch ) as any ,
@@ -1765,7 +1765,7 @@ export class RouterCore<
17651765 publicHref :
17661766 rewrittenUrl . pathname + rewrittenUrl . search + rewrittenUrl . hash ,
17671767 href : fullPath ,
1768- url : rewrittenUrl . href ,
1768+ url : rewrittenUrl ,
17691769 pathname : nextPathname ,
17701770 search : nextSearch ,
17711771 searchStr,
@@ -2000,7 +2000,7 @@ export class RouterCore<
20002000 if ( reloadDocument ) {
20012001 if ( ! href ) {
20022002 const location = this . buildLocation ( { to, ...rest } as any )
2003- href = location . url
2003+ href = location . url . href
20042004 }
20052005
20062006 // Check blockers for external URLs unless ignoreBlocker is true
@@ -2056,24 +2056,11 @@ export class RouterCore<
20562056 _includeValidateSearch : true ,
20572057 } )
20582058
2059- // Normalize URLs for comparison to handle encoding differences
2060- // Browser history always stores encoded URLs while buildLocation may produce decoded URLs
2061- const normalizeUrl = ( url : string ) => {
2062- try {
2063- return encodeURI ( decodeURI ( url ) )
2064- } catch {
2065- return url
2066- }
2067- }
2068-
20692059 if (
2070- trimPath ( normalizeUrl ( this . latestLocation . href ) ) !==
2071- trimPath ( normalizeUrl ( nextLocation . href ) )
2060+ this . latestLocation . publicHref !== nextLocation . publicHref ||
2061+ nextLocation . url . origin !== this . origin
20722062 ) {
2073- let href = nextLocation . url
2074- if ( this . origin && href . startsWith ( this . origin ) ) {
2075- href = href . replace ( this . origin , '' ) || '/'
2076- }
2063+ const href = this . getParsedLocationHref ( nextLocation )
20772064
20782065 throw redirect ( { href } )
20792066 }
@@ -2395,13 +2382,18 @@ export class RouterCore<
23952382 return this . load ( { sync : opts ?. sync } )
23962383 }
23972384
2385+ getParsedLocationHref = ( location : ParsedLocation ) => {
2386+ let href = location . url . href
2387+ if ( this . origin && location . url . origin !== this . origin ) {
2388+ href = href . replace ( this . origin , '' ) || '/'
2389+ }
2390+ return href
2391+ }
2392+
23982393 resolveRedirect = ( redirect : AnyRedirect ) : AnyRedirect => {
23992394 if ( ! redirect . options . href ) {
24002395 const location = this . buildLocation ( redirect . options )
2401- let href = location . url
2402- if ( this . origin && href . startsWith ( this . origin ) ) {
2403- href = href . replace ( this . origin , '' ) || '/'
2404- }
2396+ const href = this . getParsedLocationHref ( location )
24052397 redirect . options . href = location . href
24062398 redirect . headers . set ( 'Location' , href )
24072399 }
0 commit comments