MCPcopy
hub / github.com/TanStack/router / parseHref

Function parseHref

packages/history/src/index.ts:652–684  ·  view source on GitHub ↗
(
  href: string,
  state: ParsedHistoryState | undefined,
)

Source from the content-addressed store, hash-verified

650}
651
652export function parseHref(
653 href: string,
654 state: ParsedHistoryState | undefined,
655): HistoryLocation {
656 const sanitizedHref = sanitizePath(href)
657 const hashIndex = sanitizedHref.indexOf('#')
658 const searchIndex = sanitizedHref.indexOf('?')
659
660 const addedKey = createRandomKey()
661
662 return {
663 href: sanitizedHref,
664 pathname: sanitizedHref.substring(
665 0,
666 hashIndex > 0
667 ? searchIndex > 0
668 ? Math.min(hashIndex, searchIndex)
669 : hashIndex
670 : searchIndex > 0
671 ? searchIndex
672 : sanitizedHref.length,
673 ),
674 hash: hashIndex > -1 ? sanitizedHref.substring(hashIndex) : '',
675 search:
676 searchIndex > -1
677 ? sanitizedHref.slice(
678 searchIndex,
679 hashIndex === -1 ? undefined : hashIndex,
680 )
681 : '',
682 state: state || { [stateIndexKey]: 0, key: addedKey, __TSR_key: addedKey },
683 }
684}
685
686// Thanks co-pilot!
687function createRandomKey() {

Callers 7

RouterCoreClass · 0.90
parseHref.test.tsFile · 0.90
tryNavigationFunction · 0.85
createBrowserHistoryFunction · 0.85
queueHistoryActionFunction · 0.85
createHashHistoryFunction · 0.85
getLocationFunction · 0.85

Calls 3

sanitizePathFunction · 0.85
createRandomKeyFunction · 0.85
minMethod · 0.45

Tested by

no test coverage detected