MCPcopy Create free account
hub / github.com/TanStack/router / parse

Method parse

packages/router-core/src/router.ts:1311–1367  ·  view source on GitHub ↗
({
      pathname,
      search,
      hash,
      href,
      state,
    }: HistoryLocation)

Source from the content-addressed store, hash-verified

1309 previousLocation,
1310 ) => {
1311 const parse = ({
1312 pathname,
1313 search,
1314 hash,
1315 href,
1316 state,
1317 }: HistoryLocation): ParsedLocation<FullSearchSchema<TRouteTree>> => {
1318 // Fast path: no rewrite configured and pathname doesn't need encoding
1319 // Characters that need encoding: space, high unicode, control chars
1320 // eslint-disable-next-line no-control-regex
1321 if (!this.rewrite && !/[ \x00-\x1f\x7f\u0080-\uffff]/.test(pathname)) {
1322 const parsedSearch = this.options.parseSearch(search)
1323 const searchStr = this.options.stringifySearch(parsedSearch)
1324
1325 return {
1326 href: pathname + searchStr + hash,
1327 publicHref: pathname + searchStr + hash,
1328 pathname: decodePath(pathname).path,
1329 external: false,
1330 searchStr,
1331 search: nullReplaceEqualDeep(
1332 previousLocation?.search,
1333 parsedSearch,
1334 ) as any,
1335 hash: decodePath(hash.slice(1)).path,
1336 state: replaceEqualDeep(previousLocation?.state, state),
1337 }
1338 }
1339
1340 // Before we do any processing, we need to allow rewrites to modify the URL
1341 // build up the full URL by combining the href from history with the router's origin
1342 const fullUrl = new URL(href, this.origin)
1343
1344 const url = executeRewriteInput(this.rewrite, fullUrl)
1345
1346 const parsedSearch = this.options.parseSearch(url.search)
1347 const searchStr = this.options.stringifySearch(parsedSearch)
1348 // Make sure our final url uses the re-stringified pathname, search, and has for consistency
1349 // (We were already doing this, so just keeping it for now)
1350 url.search = searchStr
1351
1352 const fullPath = url.href.replace(url.origin, '')
1353
1354 return {
1355 href: fullPath,
1356 publicHref: href,
1357 pathname: decodePath(url.pathname).path,
1358 external: !!this.rewrite && url.origin !== this.origin,
1359 searchStr,
1360 search: nullReplaceEqualDeep(
1361 previousLocation?.search,
1362 parsedSearch,
1363 ) as any,
1364 hash: decodePath(url.hash.slice(1)).path,
1365 state: replaceEqualDeep(previousLocation?.state, state),
1366 }
1367 }
1368

Callers 15

validateSearchFunction · 0.80
validateParseParamsFunction · 0.80
syncFunction · 0.80
asyncFunction · 0.80
streamFunction · 0.80
syncFunction · 0.80
asyncFunction · 0.80
streamFunction · 0.80
streamFunction · 0.80
syncFunction · 0.80

Calls 5

decodePathFunction · 0.90
nullReplaceEqualDeepFunction · 0.90
replaceEqualDeepFunction · 0.90
executeRewriteInputFunction · 0.90
replaceMethod · 0.65

Tested by

no test coverage detected