( href: string, state: ParsedHistoryState | undefined, )
| 650 | } |
| 651 | |
| 652 | export 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! |
| 687 | function createRandomKey() { |
no test coverage detected