@@ -1252,9 +1252,34 @@ export class RouterCore<
12521252 previousLocation ,
12531253 ) => {
12541254 const parse = ( {
1255+ pathname,
1256+ search,
1257+ hash,
12551258 href,
12561259 state,
12571260 } : HistoryLocation ) : ParsedLocation < FullSearchSchema < TRouteTree > > => {
1261+ // Fast path: no rewrite configured and pathname doesn't need encoding
1262+ // Characters that need encoding: space, high unicode, control chars
1263+ // eslint-disable-next-line no-control-regex
1264+ if ( ! this . rewrite && ! / [ \x00 - \x1f \x7f \u0080 - \uffff ] / . test ( pathname ) ) {
1265+ const parsedSearch = this . options . parseSearch ( search )
1266+ const searchStr = this . options . stringifySearch ( parsedSearch )
1267+
1268+ return {
1269+ href : pathname + searchStr + hash ,
1270+ publicHref : href ,
1271+ pathname : decodePath ( pathname ) ,
1272+ external : false ,
1273+ searchStr,
1274+ search : replaceEqualDeep (
1275+ previousLocation ?. search ,
1276+ parsedSearch ,
1277+ ) as any ,
1278+ hash : decodePath ( hash . slice ( 1 ) ) ,
1279+ state : replaceEqualDeep ( previousLocation ?. state , state ) ,
1280+ }
1281+ }
1282+
12581283 // Before we do any processing, we need to allow rewrites to modify the URL
12591284 // build up the full URL by combining the href from history with the router's origin
12601285 const fullUrl = new URL ( href , this . origin )
@@ -1276,7 +1301,7 @@ export class RouterCore<
12761301 external : ! ! this . rewrite && url . origin !== this . origin ,
12771302 searchStr,
12781303 search : replaceEqualDeep ( previousLocation ?. search , parsedSearch ) as any ,
1279- hash : decodePath ( url . hash . split ( '#' ) . reverse ( ) [ 0 ] ?? '' ) ,
1304+ hash : decodePath ( url . hash . slice ( 1 ) ) ,
12801305 state : replaceEqualDeep ( previousLocation ?. state , state ) ,
12811306 }
12821307 }
0 commit comments