({
pathname,
search,
hash,
href,
state,
}: HistoryLocation)
| 1277 | previousLocation, |
| 1278 | ) => { |
| 1279 | const parse = ({ |
| 1280 | pathname, |
| 1281 | search, |
| 1282 | hash, |
| 1283 | href, |
| 1284 | state, |
| 1285 | }: HistoryLocation): ParsedLocation<FullSearchSchema<TRouteTree>> => { |
| 1286 | // Fast path: no rewrite configured and pathname doesn't need encoding |
| 1287 | // Characters that need encoding: space, high unicode, control chars |
| 1288 | // eslint-disable-next-line no-control-regex |
| 1289 | if (!this.rewrite && !/[ \x00-\x1f\x7f\u0080-\uffff]/.test(pathname)) { |
| 1290 | const parsedSearch = this.options.parseSearch(search) |
| 1291 | const searchStr = this.options.stringifySearch(parsedSearch) |
| 1292 | |
| 1293 | return { |
| 1294 | href: pathname + searchStr + hash, |
| 1295 | publicHref: href, |
| 1296 | pathname: decodePath(pathname).path, |
| 1297 | external: false, |
| 1298 | searchStr, |
| 1299 | search: nullReplaceEqualDeep( |
| 1300 | previousLocation?.search, |
| 1301 | parsedSearch, |
| 1302 | ) as any, |
| 1303 | hash: decodePath(hash.slice(1)).path, |
| 1304 | state: replaceEqualDeep(previousLocation?.state, state), |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | // Before we do any processing, we need to allow rewrites to modify the URL |
| 1309 | // build up the full URL by combining the href from history with the router's origin |
| 1310 | const fullUrl = new URL(href, this.origin) |
| 1311 | |
| 1312 | const url = executeRewriteInput(this.rewrite, fullUrl) |
| 1313 | |
| 1314 | const parsedSearch = this.options.parseSearch(url.search) |
| 1315 | const searchStr = this.options.stringifySearch(parsedSearch) |
| 1316 | // Make sure our final url uses the re-stringified pathname, search, and has for consistency |
| 1317 | // (We were already doing this, so just keeping it for now) |
| 1318 | url.search = searchStr |
| 1319 | |
| 1320 | const fullPath = url.href.replace(url.origin, '') |
| 1321 | |
| 1322 | return { |
| 1323 | href: fullPath, |
| 1324 | publicHref: href, |
| 1325 | pathname: decodePath(url.pathname).path, |
| 1326 | external: !!this.rewrite && url.origin !== this.origin, |
| 1327 | searchStr, |
| 1328 | search: nullReplaceEqualDeep( |
| 1329 | previousLocation?.search, |
| 1330 | parsedSearch, |
| 1331 | ) as any, |
| 1332 | hash: decodePath(url.hash.slice(1)).path, |
| 1333 | state: replaceEqualDeep(previousLocation?.state, state), |
| 1334 | } |
| 1335 | } |
| 1336 |
no test coverage detected