| 1 |
|
| 2 | import { History, To } from "../router/history.js";
|
| 3 | import { DataStrategyFunction, HTMLFormMethod, PatchRoutesOnNavigationFunction, RouteObject } from "../router/utils.js";
|
| 4 | import { BlockerFunction, Fetcher, FutureConfig, GetScrollRestorationKeyFunction, HydrationState, RelativeRoutingType, Router, RouterInit } from "../router/router.js";
|
| 5 | import { NavigateOptions } from "../context.js";
|
| 6 | import { FetcherSubmitOptions, SubmitOptions, SubmitTarget, URLSearchParamsInit } from "./dom.js";
|
| 7 | import { DiscoverBehavior, PrefetchBehavior, ScriptsProps } from "./ssr/components.js";
|
| 8 | import { SerializeFrom } from "../types/route-data.js";
|
| 9 | import { ClientInstrumentation } from "../router/instrumentation.js";
|
| 10 | import * as React$1 from "react";
|
| 11 |
|
| 12 |
|
| 13 | |
| 14 | |
| 15 |
|
| 16 | interface DOMRouterOpts {
|
| 17 | |
| 18 | |
| 19 |
|
| 20 | basename?: string;
|
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 |
|
| 45 | getContext?: RouterInit["getContext"];
|
| 46 | |
| 47 | |
| 48 |
|
| 49 | future?: Partial<FutureConfig>;
|
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 |
|
| 118 | hydrationData?: HydrationState;
|
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 |
|
| 167 | instrumentations?: ClientInstrumentation[];
|
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 |
|
| 196 | dataStrategy?: DataStrategyFunction;
|
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 |
|
| 494 | patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
|
| 495 | |
| 496 | |
| 497 | |
| 498 |
|
| 499 | window?: Window;
|
| 500 | }
|
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | |
| 521 | |
| 522 | |
| 523 | |
| 524 |
|
| 525 | declare function createBrowserRouter(routes: RouteObject[], opts?: DOMRouterOpts): Router;
|
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 |
|
| 549 | declare function createHashRouter(routes: RouteObject[], opts?: DOMRouterOpts): Router;
|
| 550 | |
| 551 | |
| 552 |
|
| 553 | interface BrowserRouterProps {
|
| 554 | |
| 555 | |
| 556 |
|
| 557 | basename?: string;
|
| 558 | |
| 559 | |
| 560 |
|
| 561 | children?: React$1.ReactNode;
|
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 |
|
| 576 | useTransitions?: boolean;
|
| 577 | |
| 578 | |
| 579 | |
| 580 |
|
| 581 | window?: Window;
|
| 582 | }
|
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 |
|
| 598 | declare function BrowserRouter({
|
| 599 | basename,
|
| 600 | children,
|
| 601 | useTransitions,
|
| 602 | window
|
| 603 | }: BrowserRouterProps): React$1.JSX.Element;
|
| 604 | |
| 605 | |
| 606 |
|
| 607 | interface HashRouterProps {
|
| 608 | |
| 609 | |
| 610 |
|
| 611 | basename?: string;
|
| 612 | |
| 613 | |
| 614 |
|
| 615 | children?: React$1.ReactNode;
|
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 |
|
| 630 | useTransitions?: boolean;
|
| 631 | |
| 632 | |
| 633 | |
| 634 |
|
| 635 | window?: Window;
|
| 636 | }
|
| 637 | |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 |
|
| 653 | declare function HashRouter({
|
| 654 | basename,
|
| 655 | children,
|
| 656 | useTransitions,
|
| 657 | window
|
| 658 | }: HashRouterProps): React$1.JSX.Element;
|
| 659 | |
| 660 | |
| 661 |
|
| 662 | interface HistoryRouterProps {
|
| 663 | |
| 664 | |
| 665 |
|
| 666 | basename?: string;
|
| 667 | |
| 668 | |
| 669 |
|
| 670 | children?: React$1.ReactNode;
|
| 671 | |
| 672 | |
| 673 |
|
| 674 | history: History;
|
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 |
|
| 689 | useTransitions?: boolean;
|
| 690 | }
|
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | |
| 707 | |
| 708 | |
| 709 |
|
| 710 | declare function HistoryRouter({
|
| 711 | basename,
|
| 712 | children,
|
| 713 | history,
|
| 714 | useTransitions
|
| 715 | }: HistoryRouterProps): React$1.JSX.Element;
|
| 716 | declare namespace HistoryRouter {
|
| 717 | var displayName: string;
|
| 718 | }
|
| 719 | |
| 720 | |
| 721 |
|
| 722 | interface LinkProps extends Omit<React$1.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
|
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | |
| 734 |
|
| 735 | discover?: DiscoverBehavior;
|
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | |
| 742 | |
| 743 | |
| 744 | |
| 745 | |
| 746 | |
| 747 | |
| 748 | |
| 749 | |
| 750 | |
| 751 | |
| 752 | |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | |
| 764 |
|
| 765 | prefetch?: PrefetchBehavior;
|
| 766 | |
| 767 | |
| 768 | |
| 769 | |
| 770 | |
| 771 | |
| 772 | |
| 773 | |
| 774 |
|
| 775 | reloadDocument?: boolean;
|
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 |
|
| 795 | replace?: boolean;
|
| 796 | |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 |
|
| 815 | state?: any;
|
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 | |
| 825 |
|
| 826 | preventScrollReset?: boolean;
|
| 827 | |
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 |
|
| 848 | relative?: RelativeRoutingType;
|
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | |
| 862 | |
| 863 |
|
| 864 | to: To;
|
| 865 | |
| 866 | |
| 867 | |
| 868 | |
| 869 | |
| 870 | |
| 871 | |
| 872 | |
| 873 | |
| 874 | |
| 875 | |
| 876 |
|
| 877 | viewTransition?: boolean;
|
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | |
| 890 | |
| 891 | |
| 892 |
|
| 893 | defaultShouldRevalidate?: boolean;
|
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | |
| 905 | |
| 906 | |
| 907 | |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | |
| 926 | |
| 927 | |
| 928 | |
| 929 | |
| 930 | |
| 931 | |
| 932 | |
| 933 | |
| 934 | |
| 935 | |
| 936 | |
| 937 | |
| 938 | |
| 939 | |
| 940 |
|
| 941 | mask?: To;
|
| 942 | }
|
| 943 | |
| 944 | |
| 945 | |
| 946 | |
| 947 | |
| 948 | |
| 949 | |
| 950 | |
| 951 | |
| 952 | |
| 953 | |
| 954 | |
| 955 | |
| 956 | |
| 957 | |
| 958 | |
| 959 | |
| 960 | |
| 961 | |
| 962 | |
| 963 | |
| 964 | |
| 965 | |
| 966 | |
| 967 | |
| 968 | |
| 969 | |
| 970 | |
| 971 | |
| 972 | |
| 973 |
|
| 974 | declare const Link: React$1.ForwardRefExoticComponent<LinkProps & React$1.RefAttributes<HTMLAnchorElement>>;
|
| 975 | |
| 976 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | |
| 981 | |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | |
| 987 | |
| 988 | |
| 989 | |
| 990 | |
| 991 | |
| 992 | |
| 993 | |
| 994 | |
| 995 | |
| 996 | |
| 997 | |
| 998 | |
| 999 | |
| 1000 | |
| 1001 | |
| 1002 | |
| 1003 | |
| 1004 | |
| 1005 | |
| 1006 | |
| 1007 | |
| 1008 | |
| 1009 |
|
| 1010 | type NavLinkRenderProps = {
|
| 1011 | |
| 1012 | |
| 1013 |
|
| 1014 | isActive: boolean;
|
| 1015 | |
| 1016 | |
| 1017 | |
| 1018 |
|
| 1019 | isPending: boolean;
|
| 1020 | |
| 1021 | |
| 1022 | |
| 1023 |
|
| 1024 | isTransitioning: boolean;
|
| 1025 | };
|
| 1026 | |
| 1027 | |
| 1028 |
|
| 1029 | interface NavLinkProps extends Omit<LinkProps, "className" | "style" | "children"> {
|
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | |
| 1036 | |
| 1037 | |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 |
|
| 1042 | children?: React$1.ReactNode | ((props: NavLinkRenderProps) => React$1.ReactNode);
|
| 1043 | /**
|
| 1044 | * Changes the matching logic to make it case-sensitive:
|
| 1045 | *
|
| 1046 | * | Link | URL | isActive |
|
| 1047 | * | -------------------------------------------- | ------------- | -------- |
|
| 1048 | * | `<NavLink to="/SpOnGe-bOB" />` | `/sponge-bob` | true |
|
| 1049 | * | `<NavLink to="/SpOnGe-bOB" caseSensitive />` | `/sponge-bob` | false |
|
| 1050 | */
|
| 1051 | caseSensitive?: boolean;
|
| 1052 | /**
|
| 1053 | * Classes are automatically applied to `NavLink` that correspond to the state.
|
| 1054 | *
|
| 1055 | * ```css
|
| 1056 | * a.active {
|
| 1057 | * color: red;
|
| 1058 | * }
|
| 1059 | * a.pending {
|
| 1060 | * color: blue;
|
| 1061 | * }
|
| 1062 | * a.transitioning {
|
| 1063 | * view-transition-name: my-transition;
|
| 1064 | * }
|
| 1065 | * ```
|
| 1066 | *
|
| 1067 | * Or you can specify a function that receives {@link NavLinkRenderProps} and
|
| 1068 | * returns the `className`:
|
| 1069 | *
|
| 1070 | * ```tsx
|
| 1071 | * <NavLink className={({ isActive, isPending }) => (
|
| 1072 | * isActive ? "my-active-class" :
|
| 1073 | * isPending ? "my-pending-class" :
|
| 1074 | * ""
|
| 1075 | * )} />
|
| 1076 | * ```
|
| 1077 | */
|
| 1078 | className?: string | ((props: NavLinkRenderProps) => string | undefined);
|
| 1079 | /**
|
| 1080 | * Changes the matching logic for the `active` and `pending` states to only match
|
| 1081 | * to the "end" of the {@link NavLinkProps.to}. If the URL is longer, it will no
|
| 1082 | * longer be considered active.
|
| 1083 | *
|
| 1084 | * | Link | URL | isActive |
|
| 1085 | * | ----------------------------- | ------------ | -------- |
|
| 1086 | * | `<NavLink to="/tasks" />` | `/tasks` | true |
|
| 1087 | * | `<NavLink to="/tasks" />` | `/tasks/123` | true |
|
| 1088 | * | `<NavLink to="/tasks" end />` | `/tasks` | true |
|
| 1089 | * | `<NavLink to="/tasks" end />` | `/tasks/123` | false |
|
| 1090 | *
|
| 1091 | * `<NavLink to="/">` is an exceptional case because _every_ URL matches `/`.
|
| 1092 | * To avoid this matching every single route by default, it effectively ignores
|
| 1093 | * the `end` prop and only matches when you're at the root route.
|
| 1094 | */
|
| 1095 | end?: boolean;
|
| 1096 | /**
|
| 1097 | * Styles can also be applied dynamically via a function that receives
|
| 1098 | * {@link NavLinkRenderProps} and returns the styles:
|
| 1099 | *
|
| 1100 | * ```tsx
|
| 1101 | * <NavLink to="/tasks" style={{ color: "red" }} />
|
| 1102 | * <NavLink to="/tasks" style={({ isActive, isPending }) => ({
|
| 1103 | * color:
|
| 1104 | * isActive ? "red" :
|
| 1105 | * isPending ? "blue" : "black"
|
| 1106 | * })} />
|
| 1107 | * ```
|
| 1108 | */
|
| 1109 | style?: React$1.CSSProperties | ((props: NavLinkRenderProps) => React$1.CSSProperties | undefined);
|
| 1110 | }
|
| 1111 | /**
|
| 1112 | * Wraps {@link Link | `<Link>`} with additional props for styling active and
|
| 1113 | * pending states.
|
| 1114 | *
|
| 1115 | * - Automatically applies classes to the link based on its `active` and `pending`
|
| 1116 | * states, see {@link NavLinkProps.className}
|
| 1117 | * - Note that `pending` is only available with Framework and Data modes.
|
| 1118 | * - Automatically applies `aria-current="page"` to the link when the link is active.
|
| 1119 | * See [`aria-current`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current)
|
| 1120 | * on MDN.
|
| 1121 | * - States are additionally available through the className, style, and children
|
| 1122 | * render props. See {@link NavLinkRenderProps}.
|
| 1123 | *
|
| 1124 | * @example
|
| 1125 | * <NavLink to="/message">Messages</NavLink>
|
| 1126 | *
|
| 1127 | * // Using render props
|
| 1128 | * <NavLink
|
| 1129 | * to="/messages"
|
| 1130 | * className={({ isActive, isPending }) =>
|
| 1131 | * isPending ? "pending" : isActive ? "active" : ""
|
| 1132 | * }
|
| 1133 | * >
|
| 1134 | * Messages
|
| 1135 | * </NavLink>
|
| 1136 | *
|
| 1137 | * @public
|
| 1138 | * @category Components
|
| 1139 | * @param {NavLinkProps.caseSensitive} props.caseSensitive n/a
|
| 1140 | * @param {NavLinkProps.children} props.children n/a
|
| 1141 | * @param {NavLinkProps.className} props.className n/a
|
| 1142 | * @param {NavLinkProps.discover} props.discover [modes: framework] n/a
|
| 1143 | * @param {NavLinkProps.end} props.end n/a
|
| 1144 | * @param {NavLinkProps.prefetch} props.prefetch [modes: framework] n/a
|
| 1145 | * @param {NavLinkProps.preventScrollReset} props.preventScrollReset [modes: framework, data] n/a
|
| 1146 | * @param {NavLinkProps.relative} props.relative n/a
|
| 1147 | * @param {NavLinkProps.reloadDocument} props.reloadDocument n/a
|
| 1148 | * @param {NavLinkProps.replace} props.replace n/a
|
| 1149 | * @param {NavLinkProps.state} props.state n/a
|
| 1150 | * @param {NavLinkProps.style} props.style n/a
|
| 1151 | * @param {NavLinkProps.to} props.to n/a
|
| 1152 | * @param {NavLinkProps.viewTransition} props.viewTransition [modes: framework, data] n/a
|
| 1153 | */
|
| 1154 | declare const NavLink: React$1.ForwardRefExoticComponent<NavLinkProps & React$1.RefAttributes<HTMLAnchorElement>>;
|
| 1155 | /**
|
| 1156 | * Form props shared by navigations and fetchers
|
| 1157 | */
|
| 1158 | interface SharedFormProps extends React$1.FormHTMLAttributes<HTMLFormElement> {
|
| 1159 | /**
|
| 1160 | * The HTTP verb to use when the form is submitted. Supports `"delete"`,
|
| 1161 | * `"get"`, `"patch"`, `"post"`, and `"put"`.
|
| 1162 | *
|
| 1163 | * Native [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)
|
| 1164 | * only supports `"get"` and `"post"`, avoid the other verbs if you'd like to
|
| 1165 | * support progressive enhancement
|
| 1166 | */
|
| 1167 | method?: HTMLFormMethod;
|
| 1168 | /**
|
| 1169 | * The encoding type to use for the form submission.
|
| 1170 | *
|
| 1171 | * ```tsx
|
| 1172 | * <Form encType="application/x-www-form-urlencoded"/>
|
| 1173 | * <Form encType="multipart/form-data"/>
|
| 1174 | * <Form encType="text/plain"/>
|
| 1175 | * ```
|
| 1176 | */
|
| 1177 | encType?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
|
| 1178 | /**
|
| 1179 | * The URL to submit the form data to. If `undefined`, this defaults to the
|
| 1180 | * closest route in context.
|
| 1181 | */
|
| 1182 | action?: string;
|
| 1183 | /**
|
| 1184 | * Determines whether the form action is relative to the route hierarchy or
|
| 1185 | * the pathname. Use this if you want to opt out of navigating the route
|
| 1186 | * hierarchy and want to instead route based on slash-delimited URL segments.
|
| 1187 | * See {@link RelativeRoutingType}.
|
| 1188 | */
|
| 1189 | relative?: RelativeRoutingType;
|
| 1190 | /**
|
| 1191 | * Prevent the scroll position from resetting to the top of the viewport on
|
| 1192 | * completion of the navigation when using the
|
| 1193 | * {@link ScrollRestoration | `<ScrollRestoration>`} component
|
| 1194 | */
|
| 1195 | preventScrollReset?: boolean;
|
| 1196 | /**
|
| 1197 | * Specify the default revalidation behavior after this submission
|
| 1198 | *
|
| 1199 | * If no `shouldRevalidate` functions are present on the active routes, then this
|
| 1200 | * value will be used directly. Otherwise it will be passed into `shouldRevalidate`
|
| 1201 | * so the route can make the final determination on revalidation. This can be
|
| 1202 | * useful when updating search params and you don't want to trigger a revalidation.
|
| 1203 | *
|
| 1204 | * By default (when not specified), loaders will revalidate according to the routers
|
| 1205 | * standard revalidation behavior.
|
| 1206 | */
|
| 1207 | defaultShouldRevalidate?: boolean;
|
| 1208 | }
|
| 1209 | /**
|
| 1210 | * Form props available to fetchers
|
| 1211 | * @category Types
|
| 1212 | */
|
| 1213 | interface FetcherFormProps extends SharedFormProps {}
|
| 1214 | /**
|
| 1215 | * Form props available to navigations
|
| 1216 | * @category Types
|
| 1217 | */
|
| 1218 | interface FormProps extends SharedFormProps {
|
| 1219 | /**
|
| 1220 | * Defines the form [lazy route discovery](../../explanation/lazy-route-discovery) behavior.
|
| 1221 | *
|
| 1222 | * - **render** — default, discover the route when the form renders
|
| 1223 | * - **none** — don't eagerly discover, only discover if the form is submitted
|
| 1224 | *
|
| 1225 | * ```tsx
|
| 1226 | * <Form />
|
| 1227 | * <Form discover="render" />
|
| 1228 | * <Form discover="none" />
|
| 1229 | * ```
|
| 1230 | */
|
| 1231 | discover?: DiscoverBehavior;
|
| 1232 | /**
|
| 1233 | * Indicates a specific fetcherKey to use when using `navigate={false}` so you
|
| 1234 | * can pick up the fetcher's state in a different component in a {@link useFetcher}.
|
| 1235 | */
|
| 1236 | fetcherKey?: string;
|
| 1237 | /**
|
| 1238 | * When `false`, skips the navigation and submits via a fetcher internally.
|
| 1239 | * This is essentially a shorthand for {@link useFetcher} + `<fetcher.Form>` where
|
| 1240 | * you don't care about the resulting data in this component.
|
| 1241 | */
|
| 1242 | navigate?: boolean;
|
| 1243 | /**
|
| 1244 | * Forces a full document navigation instead of client side routing and data
|
| 1245 | * fetch.
|
| 1246 | */
|
| 1247 | reloadDocument?: boolean;
|
| 1248 | /**
|
| 1249 | * Replaces the current entry in the browser [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
|
| 1250 | * stack when the form navigates. Use this if you don't want the user to be
|
| 1251 | * able to click "back" to the page with the form on it.
|
| 1252 | */
|
| 1253 | replace?: boolean;
|
| 1254 | /**
|
| 1255 | * State object to add to the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
|
| 1256 | * stack entry for this navigation
|
| 1257 | */
|
| 1258 | state?: any;
|
| 1259 | /**
|
| 1260 | * Enables a [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)
|
| 1261 | * for this navigation. To apply specific styles during the transition, see
|
| 1262 | * {@link useViewTransitionState}.
|
| 1263 | */
|
| 1264 | viewTransition?: boolean;
|
| 1265 | }
|
| 1266 | /**
|
| 1267 | * A progressively enhanced HTML [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)
|
| 1268 | * that submits data to actions via [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch),
|
| 1269 | * activating pending states in {@link useNavigation} which enables advanced
|
| 1270 | * user interfaces beyond a basic HTML [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form).
|
| 1271 | * After a form's `action` completes, all data on the page is automatically
|
| 1272 | * revalidated to keep the UI in sync with the data.
|
| 1273 | *
|
| 1274 | * Because it uses the HTML form API, server rendered pages are interactive at a
|
| 1275 | * basic level before JavaScript loads. Instead of React Router managing the
|
| 1276 | * submission, the browser manages the submission as well as the pending states
|
| 1277 | * (like the spinning favicon). After JavaScript loads, React Router takes over
|
| 1278 | * enabling web application user experiences.
|
| 1279 | *
|
| 1280 | * `Form` is most useful for submissions that should also change the URL or
|
| 1281 | * otherwise add an entry to the browser history stack. For forms that shouldn't
|
| 1282 | * manipulate the browser [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
|
| 1283 | * stack, use {@link FetcherWithComponents.Form | `<fetcher.Form>`}.
|
| 1284 | *
|
| 1285 | * @example
|
| 1286 | * import { Form } from "react-router";
|
| 1287 | *
|
| 1288 | * function NewEvent() {
|
| 1289 | * return (
|
| 1290 | * <Form action="/events" method="post">
|
| 1291 | * <input name="title" type="text" />
|
| 1292 | * <input name="description" type="text" />
|
| 1293 | * </Form>
|
| 1294 | * );
|
| 1295 | * }
|
| 1296 | *
|
| 1297 | * @public
|
| 1298 | * @category Components
|
| 1299 | * @mode framework
|
| 1300 | * @mode data
|
| 1301 | * @param {FormProps.action} action n/a
|
| 1302 | * @param {FormProps.discover} discover n/a
|
| 1303 | * @param {FormProps.encType} encType n/a
|
| 1304 | * @param {FormProps.fetcherKey} fetcherKey n/a
|
| 1305 | * @param {FormProps.method} method n/a
|
| 1306 | * @param {FormProps.navigate} navigate n/a
|
| 1307 | * @param {FormProps.preventScrollReset} preventScrollReset n/a
|
| 1308 | * @param {FormProps.relative} relative n/a
|
| 1309 | * @param {FormProps.reloadDocument} reloadDocument n/a
|
| 1310 | * @param {FormProps.replace} replace n/a
|
| 1311 | * @param {FormProps.state} state n/a
|
| 1312 | * @param {FormProps.viewTransition} viewTransition n/a
|
| 1313 | * @param {FormProps.defaultShouldRevalidate} defaultShouldRevalidate n/a
|
| 1314 | * @returns A progressively enhanced [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) component
|
| 1315 | */
|
| 1316 | declare const Form: React$1.ForwardRefExoticComponent<FormProps & React$1.RefAttributes<HTMLFormElement>>;
|
| 1317 | type ScrollRestorationProps = ScriptsProps & {
|
| 1318 | /**
|
| 1319 | * A function that returns a key to use for scroll restoration. This is useful
|
| 1320 | * for custom scroll restoration logic, such as using only the pathname so
|
| 1321 | * that later navigations to prior paths will restore the scroll. Defaults to
|
| 1322 | * `location.key`. See {@link GetScrollRestorationKeyFunction}.
|
| 1323 | *
|
| 1324 | * ```tsx
|
| 1325 | * <ScrollRestoration
|
| 1326 | * getKey={(location, matches) => {
|
| 1327 | *
|
| 1328 | * return location.key
|
| 1329 | *
|
| 1330 | *
|
| 1331 | * return location.pathname
|
| 1332 | * }}
|
| 1333 | * />
|
| 1334 | * ```
|
| 1335 | */
|
| 1336 | getKey?: GetScrollRestorationKeyFunction;
|
| 1337 | /**
|
| 1338 | * The key to use for storing scroll positions in [`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage).
|
| 1339 | * Defaults to `"react-router-scroll-positions"`.
|
| 1340 | */
|
| 1341 | storageKey?: string;
|
| 1342 | };
|
| 1343 | /**
|
| 1344 | * Emulates the browser's scroll restoration on location changes. Apps should only render one of these, right before the {@link Scripts} component.
|
| 1345 | *
|
| 1346 | * ```tsx
|
| 1347 | * import { ScrollRestoration } from "react-router";
|
| 1348 | *
|
| 1349 | * export default function Root() {
|
| 1350 | * return (
|
| 1351 | * <html>
|
| 1352 | * <body>
|
| 1353 | * <ScrollRestoration />
|
| 1354 | * <Scripts />
|
| 1355 | * </body>
|
| 1356 | * </html>
|
| 1357 | * );
|
| 1358 | * }
|
| 1359 | * ```
|
| 1360 | *
|
| 1361 | * This component renders an inline `<script>` to prevent scroll flashing. The
|
| 1362 | * `nonce` prop will be passed down to the script tag to allow CSP nonce usage.
|
| 1363 | * If not provided in Framework Mode, it will default to any
|
| 1364 | * {@link ServerRouter | `<ServerRouter nonce>`} prop.
|
| 1365 | *
|
| 1366 | * ```tsx
|
| 1367 | * <ScrollRestoration nonce={cspNonce} />
|
| 1368 | * ```
|
| 1369 | *
|
| 1370 | * @public
|
| 1371 | * @category Components
|
| 1372 | * @mode framework
|
| 1373 | * @mode data
|
| 1374 | * @param props Props
|
| 1375 | * @param {ScrollRestorationProps.getKey} props.getKey n/a
|
| 1376 | * @param {ScriptsProps.nonce} props.nonce n/a
|
| 1377 | * @param {ScrollRestorationProps.storageKey} props.storageKey n/a
|
| 1378 | * @returns A [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
|
| 1379 | * tag that restores scroll positions on navigation.
|
| 1380 | */
|
| 1381 | declare function ScrollRestoration({
|
| 1382 | getKey,
|
| 1383 | storageKey,
|
| 1384 | ...props
|
| 1385 | }: ScrollRestorationProps): React$1.JSX.Element | null;
|
| 1386 | declare namespace ScrollRestoration {
|
| 1387 | var displayName: string;
|
| 1388 | }
|
| 1389 | /**
|
| 1390 | * Handles the click behavior for router {@link Link | `<Link>`} components.This
|
| 1391 | * is useful if you need to create custom {@link Link | `<Link>`} components with
|
| 1392 | * the same click behavior we use in our exported {@link Link | `<Link>`}.
|
| 1393 | *
|
| 1394 | * @public
|
| 1395 | * @category Hooks
|
| 1396 | * @param to The URL to navigate to, can be a string or a partial {@link Path}.
|
| 1397 | * @param options Options
|
| 1398 | * @param options.preventScrollReset Whether to prevent the scroll position from
|
| 1399 | * being reset to the top of the viewport on completion of the navigation when
|
| 1400 | * using the {@link ScrollRestoration} component. Defaults to `false`.
|
| 1401 | * @param options.relative The {@link RelativeRoutingType | relative routing type}
|
| 1402 | * to use for the link. Defaults to `"route"`.
|
| 1403 | * @param options.replace Whether to replace the current [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
|
| 1404 | * entry instead of pushing a new one. Defaults to `false`.
|
| 1405 | * @param options.state The state to add to the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
|
| 1406 | * entry for this navigation. Defaults to `undefined`.
|
| 1407 | * @param options.target The target attribute for the link. Defaults to `undefined`.
|
| 1408 | * @param options.viewTransition Enables a [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)
|
| 1409 | * for this navigation. To apply specific styles during the transition, see
|
| 1410 | * {@link useViewTransitionState}. Defaults to `false`.
|
| 1411 | * @param options.defaultShouldRevalidate Specify the default revalidation
|
| 1412 | * behavior for the navigation. Defaults to `true`.
|
| 1413 | * @param options.mask Masked location to display in the browser instead
|
| 1414 | * of the router location. Defaults to `undefined`.
|
| 1415 | * @param options.useTransitions Wraps the navigation in
|
| 1416 | * [`React.startTransition`](https://react.dev/reference/react/startTransition)
|
| 1417 | * for concurrent rendering. Defaults to `false`.
|
| 1418 | * @returns A click handler function that can be used in a custom {@link Link} component.
|
| 1419 | */
|
| 1420 | declare function useLinkClickHandler<E extends Element = HTMLAnchorElement>(to: To, {
|
| 1421 | target,
|
| 1422 | replace: replaceProp,
|
| 1423 | mask,
|
| 1424 | state,
|
| 1425 | preventScrollReset,
|
| 1426 | relative,
|
| 1427 | viewTransition,
|
| 1428 | defaultShouldRevalidate,
|
| 1429 | useTransitions
|
| 1430 | }?: {
|
| 1431 | target?: React$1.HTMLAttributeAnchorTarget;
|
| 1432 | replace?: boolean;
|
| 1433 | mask?: To;
|
| 1434 | state?: any;
|
| 1435 | preventScrollReset?: boolean;
|
| 1436 | relative?: RelativeRoutingType;
|
| 1437 | viewTransition?: boolean;
|
| 1438 | defaultShouldRevalidate?: boolean;
|
| 1439 | useTransitions?: boolean;
|
| 1440 | }): (event: React$1.MouseEvent<E, MouseEvent>) => void;
|
| 1441 | /**
|
| 1442 | * Returns a tuple of the current URL's [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
|
| 1443 | * and a function to update them. Setting the search params causes a navigation.
|
| 1444 | *
|
| 1445 | * ```tsx
|
| 1446 | * import { useSearchParams } from "react-router";
|
| 1447 | *
|
| 1448 | * export function SomeComponent() {
|
| 1449 | * const [searchParams, setSearchParams] = useSearchParams();
|
| 1450 | *
|
| 1451 | * }
|
| 1452 | * ```
|
| 1453 | *
|
| 1454 | * ### `setSearchParams` function
|
| 1455 | *
|
| 1456 | * The second element of the tuple is a function that can be used to update the
|
| 1457 | * search params. It accepts the same types as `defaultInit` and will cause a
|
| 1458 | * navigation to the new URL.
|
| 1459 | *
|
| 1460 | * ```tsx
|
| 1461 | * let [searchParams, setSearchParams] = useSearchParams();
|
| 1462 | *
|
| 1463 | *
|
| 1464 | * setSearchParams("?tab=1");
|
| 1465 | *
|
| 1466 | *
|
| 1467 | * setSearchParams({ tab: "1" });
|
| 1468 | *
|
| 1469 | *
|
| 1470 | * setSearchParams({ brand: ["nike", "reebok"] });
|
| 1471 | *
|
| 1472 | *
|
| 1473 | * setSearchParams([["tab", "1"]]);
|
| 1474 | *
|
| 1475 | *
|
| 1476 | * setSearchParams(new URLSearchParams("?tab=1"));
|
| 1477 | * ```
|
| 1478 | *
|
| 1479 | * It also supports a function callback like React's
|
| 1480 | * [`setState`](https://react.dev/reference/react/useState#setstate):
|
| 1481 | *
|
| 1482 | * ```tsx
|
| 1483 | * setSearchParams((searchParams) => {
|
| 1484 | * searchParams.set("tab", "2");
|
| 1485 | * return searchParams;
|
| 1486 | * });
|
| 1487 | * ```
|
| 1488 | *
|
| 1489 | * <docs-warning>The function callback version of `setSearchParams` does not support
|
| 1490 | * the [queueing](https://react.dev/reference/react/useState#setstate-parameters)
|
| 1491 | * logic that React's `setState` implements. Multiple calls to `setSearchParams`
|
| 1492 | * in the same tick will not build on the prior value. If you need this behavior,
|
| 1493 | * you can use `setState` manually.</docs-warning>
|
| 1494 | *
|
| 1495 | * ### Notes
|
| 1496 | *
|
| 1497 | * Note that `searchParams` is a stable reference, so you can reliably use it
|
| 1498 | * as a dependency in React's [`useEffect`](https://react.dev/reference/react/useEffect)
|
| 1499 | * hooks.
|
| 1500 | *
|
| 1501 | * ```tsx
|
| 1502 | * useEffect(() => {
|
| 1503 | * console.log(searchParams.get("tab"));
|
| 1504 | * }, [searchParams]);
|
| 1505 | * ```
|
| 1506 | *
|
| 1507 | * However, this also means it's mutable. If you change the object without
|
| 1508 | * calling `setSearchParams`, its values will change between renders if some
|
| 1509 | * other state causes the component to re-render and URL will not reflect the
|
| 1510 | * values.
|
| 1511 | *
|
| 1512 | * @public
|
| 1513 | * @category Hooks
|
| 1514 | * @param defaultInit
|
| 1515 | * You can initialize the search params with a default value, though it **will
|
| 1516 | * not** change the URL on the first render.
|
| 1517 | *
|
| 1518 | * ```tsx
|
| 1519 | *
|
| 1520 | * useSearchParams("?tab=1");
|
| 1521 | *
|
| 1522 | *
|
| 1523 | * useSearchParams({ tab: "1" });
|
| 1524 | *
|
| 1525 | *
|
| 1526 | * useSearchParams({ brand: ["nike", "reebok"] });
|
| 1527 | *
|
| 1528 | *
|
| 1529 | * useSearchParams([["tab", "1"]]);
|
| 1530 | *
|
| 1531 | *
|
| 1532 | * useSearchParams(new URLSearchParams("?tab=1"));
|
| 1533 | * ```
|
| 1534 | * @returns A tuple of the current [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
|
| 1535 | * and a function to update them.
|
| 1536 | */
|
| 1537 | declare function useSearchParams(defaultInit?: URLSearchParamsInit): [URLSearchParams, SetURLSearchParams];
|
| 1538 | /**
|
| 1539 | * Sets new search params and causes a navigation when called.
|
| 1540 | *
|
| 1541 | * ```tsx
|
| 1542 | * <button
|
| 1543 | * onClick={() => {
|
| 1544 | * const params = new URLSearchParams();
|
| 1545 | * params.set("someKey", "someValue");
|
| 1546 | * setSearchParams(params, {
|
| 1547 | * preventScrollReset: true,
|
| 1548 | * });
|
| 1549 | * }}
|
| 1550 | * />
|
| 1551 | * ```
|
| 1552 | *
|
| 1553 | * It also supports a function for setting new search params.
|
| 1554 | *
|
| 1555 | * ```tsx
|
| 1556 | * <button
|
| 1557 | * onClick={() => {
|
| 1558 | * setSearchParams((prev) => {
|
| 1559 | * prev.set("someKey", "someValue");
|
| 1560 | * return prev;
|
| 1561 | * });
|
| 1562 | * }}
|
| 1563 | * />
|
| 1564 | * ```
|
| 1565 | */
|
| 1566 | type SetURLSearchParams = (nextInit?: URLSearchParamsInit | ((prev: URLSearchParams) => URLSearchParamsInit), navigateOpts?: NavigateOptions) => void;
|
| 1567 | /**
|
| 1568 | * Submits a HTML [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)
|
| 1569 | * to the server without reloading the page.
|
| 1570 | */
|
| 1571 | interface SubmitFunction {
|
| 1572 | (
|
| 1573 | /**
|
| 1574 | * Can be multiple types of elements and objects
|
| 1575 | *
|
| 1576 | * **[`HTMLFormElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement)**
|
| 1577 | *
|
| 1578 | * ```tsx
|
| 1579 | * <Form
|
| 1580 | * onSubmit={(event) => {
|
| 1581 | * submit(event.currentTarget);
|
| 1582 | * }}
|
| 1583 | * />
|
| 1584 | * ```
|
| 1585 | *
|
| 1586 | * **[`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)**
|
| 1587 | *
|
| 1588 | * ```tsx
|
| 1589 | * const formData = new FormData();
|
| 1590 | * formData.append("myKey", "myValue");
|
| 1591 | * submit(formData, { method: "post" });
|
| 1592 | * ```
|
| 1593 | *
|
| 1594 | * **Plain object that will be serialized as [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)**
|
| 1595 | *
|
| 1596 | * ```tsx
|
| 1597 | * submit({ myKey: "myValue" }, { method: "post" });
|
| 1598 | * ```
|
| 1599 | *
|
| 1600 | * **Plain object that will be serialized as JSON**
|
| 1601 | *
|
| 1602 | * ```tsx
|
| 1603 | * submit(
|
| 1604 | * { myKey: "myValue" },
|
| 1605 | * { method: "post", encType: "application/json" }
|
| 1606 | * );
|
| 1607 | * ```
|
| 1608 | */
|
| 1609 | target: SubmitTarget,
|
| 1610 | /**
|
| 1611 | * Options that override the [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)'s
|
| 1612 | * own attributes. Required when submitting arbitrary data without a backing
|
| 1613 | * [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form).
|
| 1614 | */
|
| 1615 | options?: SubmitOptions): Promise<void>;
|
| 1616 | }
|
| 1617 | /**
|
| 1618 | * Submits a fetcher [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) to the server without reloading the page.
|
| 1619 | */
|
| 1620 | interface FetcherSubmitFunction {
|
| 1621 | (
|
| 1622 | /**
|
| 1623 | * Can be multiple types of elements and objects
|
| 1624 | *
|
| 1625 | * **[`HTMLFormElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement)**
|
| 1626 | *
|
| 1627 | * ```tsx
|
| 1628 | * <fetcher.Form
|
| 1629 | * onSubmit={(event) => {
|
| 1630 | * fetcher.submit(event.currentTarget);
|
| 1631 | * }}
|
| 1632 | * />
|
| 1633 | * ```
|
| 1634 | *
|
| 1635 | * **[`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)**
|
| 1636 | *
|
| 1637 | * ```tsx
|
| 1638 | * const formData = new FormData();
|
| 1639 | * formData.append("myKey", "myValue");
|
| 1640 | * fetcher.submit(formData, { method: "post" });
|
| 1641 | * ```
|
| 1642 | *
|
| 1643 | * **Plain object that will be serialized as [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)**
|
| 1644 | *
|
| 1645 | * ```tsx
|
| 1646 | * fetcher.submit({ myKey: "myValue" }, { method: "post" });
|
| 1647 | * ```
|
| 1648 | *
|
| 1649 | * **Plain object that will be serialized as JSON**
|
| 1650 | *
|
| 1651 | * ```tsx
|
| 1652 | * fetcher.submit(
|
| 1653 | * { myKey: "myValue" },
|
| 1654 | * { method: "post", encType: "application/json" }
|
| 1655 | * );
|
| 1656 | * ```
|
| 1657 | */
|
| 1658 | target: SubmitTarget, options?: FetcherSubmitOptions): Promise<void>;
|
| 1659 | }
|
| 1660 | /**
|
| 1661 | * The imperative version of {@link Form | `<Form>`} that lets you submit a form
|
| 1662 | * from code instead of a user interaction.
|
| 1663 | *
|
| 1664 | * @example
|
| 1665 | * import { useSubmit } from "react-router";
|
| 1666 | *
|
| 1667 | * function SomeComponent() {
|
| 1668 | * const submit = useSubmit();
|
| 1669 | * return (
|
| 1670 | * <Form onChange={(event) => submit(event.currentTarget)} />
|
| 1671 | * );
|
| 1672 | * }
|
| 1673 | *
|
| 1674 | * @public
|
| 1675 | * @category Hooks
|
| 1676 | * @mode framework
|
| 1677 | * @mode data
|
| 1678 | * @returns A function that can be called to submit a {@link Form} imperatively.
|
| 1679 | */
|
| 1680 | declare function useSubmit(): SubmitFunction;
|
| 1681 | /**
|
| 1682 | * Resolves the URL to the closest route in the component hierarchy instead of
|
| 1683 | * the current URL of the app.
|
| 1684 | *
|
| 1685 | * This is used internally by {@link Form} to resolve the `action` to the closest
|
| 1686 | * route, but can be used generically as well.
|
| 1687 | *
|
| 1688 | * ```ts
|
| 1689 | * import { useFormAction } from "react-router";
|
| 1690 | *
|
| 1691 | * function SomeComponent() {
|
| 1692 | *
|
| 1693 | * let action = useFormAction();
|
| 1694 | *
|
| 1695 | *
|
| 1696 | * let destroyAction = useFormAction("destroy");
|
| 1697 | * }
|
| 1698 | * ```
|
| 1699 | *
|
| 1700 | * <docs-info>This hook adds a `basename` if your app specifies one, so that it
|
| 1701 | * can be used with raw `<form>` elements in a progressively enhanced way. If
|
| 1702 | * you are using this to provide an `action` to `<Form>` or `fetcher.submit`, you
|
| 1703 | * will need to remove the `basename` since both of those will prepend it
|
| 1704 | * internally.</docs-info>
|
| 1705 | *
|
| 1706 | *
|
| 1707 | * @public
|
| 1708 | * @category Hooks
|
| 1709 | * @mode framework
|
| 1710 | * @mode data
|
| 1711 | * @param action The action to append to the closest route URL. Defaults to the
|
| 1712 | * closest route URL.
|
| 1713 | * @param options Options
|
| 1714 | * @param options.relative The relative routing type to use when resolving the
|
| 1715 | * action. Defaults to `"route"`.
|
| 1716 | * @returns The resolved action URL.
|
| 1717 | */
|
| 1718 | declare function useFormAction(action?: string, {
|
| 1719 | relative
|
| 1720 | }?: {
|
| 1721 | relative?: RelativeRoutingType;
|
| 1722 | }): string;
|
| 1723 | /**
|
| 1724 | * The return value {@link useFetcher} that keeps track of the state of a fetcher.
|
| 1725 | *
|
| 1726 | * ```tsx
|
| 1727 | * let fetcher = useFetcher();
|
| 1728 | * ```
|
| 1729 | */
|
| 1730 | type FetcherWithComponents<TData> = Fetcher<TData> & {
|
| 1731 | /**
|
| 1732 | * Just like {@link Form} except it doesn't cause a navigation.
|
| 1733 | *
|
| 1734 | * ```tsx
|
| 1735 | * function SomeComponent() {
|
| 1736 | * const fetcher = useFetcher()
|
| 1737 | * return (
|
| 1738 | * <fetcher.Form method="post" action="/some/route">
|
| 1739 | * <input type="text" />
|
| 1740 | * </fetcher.Form>
|
| 1741 | * )
|
| 1742 | * }
|
| 1743 | * ```
|
| 1744 | */
|
| 1745 | Form: React$1.ForwardRefExoticComponent<FetcherFormProps & React$1.RefAttributes<HTMLFormElement>>;
|
| 1746 | /**
|
| 1747 | * Loads data from a route. Useful for loading data imperatively inside user
|
| 1748 | * events outside a normal button or form, like a combobox or search input.
|
| 1749 | *
|
| 1750 | * ```tsx
|
| 1751 | * let fetcher = useFetcher()
|
| 1752 | *
|
| 1753 | * <input onChange={e => {
|
| 1754 | * fetcher.load(`/search?q=${e.target.value}`)
|
| 1755 | * }} />
|
| 1756 | * ```
|
| 1757 | */
|
| 1758 | load: (href: string, opts?: {
|
| 1759 | /**
|
| 1760 | * Wraps the initial state update for this `fetcher.load` in a
|
| 1761 | * [`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync)
|
| 1762 | * call instead of the default [`React.startTransition`](https://react.dev/reference/react/startTransition).
|
| 1763 | * This allows you to perform synchronous DOM actions immediately after the
|
| 1764 | * update is flushed to the DOM.
|
| 1765 | */
|
| 1766 | flushSync?: boolean;
|
| 1767 | }) => Promise<void>;
|
| 1768 | /**
|
| 1769 | * Reset a fetcher back to an empty/idle state.
|
| 1770 | *
|
| 1771 | * If the fetcher is currently in-flight, the
|
| 1772 | * [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
|
| 1773 | * will be aborted with the `reason`, if provided.
|
| 1774 | * @param opts Options for resetting the fetcher.
|
| 1775 | * @param opts.reason Optional `reason` to provide to [`AbortController.abort()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort)
|
| 1776 | * @returns void
|
| 1777 | */
|
| 1778 | reset: (opts?: {
|
| 1779 | reason?: unknown;
|
| 1780 | }) => void;
|
| 1781 | /**
|
| 1782 | * Submits form data to a route. While multiple nested routes can match a URL, only the leaf route will be called.
|
| 1783 | *
|
| 1784 | * The `formData` can be multiple types:
|
| 1785 | *
|
| 1786 | * - [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
|
| 1787 | * A `FormData` instance.
|
| 1788 | * - [`HTMLFormElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement)
|
| 1789 | * A [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) DOM element.
|
| 1790 | * - `Object`
|
| 1791 | * An object of key/value-pairs that will be converted to a [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
|
| 1792 | * instance by default. You can pass a more complex object and serialize it
|
| 1793 | * as JSON by specifying `encType: "application/json"`. See
|
| 1794 | * {@link useSubmit} for more details.
|
| 1795 | *
|
| 1796 | * If the method is `GET`, then the route [`loader`](../../start/framework/route-module#loader)
|
| 1797 | * is being called and with the `formData` serialized to the url as [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams).
|
| 1798 | * If `DELETE`, `PATCH`, `POST`, or `PUT`, then the route [`action`](../../start/framework/route-module#action)
|
| 1799 | * is being called with `formData` as the body.
|
| 1800 | *
|
| 1801 | * ```tsx
|
| 1802 | *
|
| 1803 | * const formData = new FormData();
|
| 1804 | * fetcher.submit(formData);
|
| 1805 | *
|
| 1806 | *
|
| 1807 | * fetcher.submit(event.currentTarget.form, {
|
| 1808 | * method: "POST",
|
| 1809 | * });
|
| 1810 | *
|
| 1811 | *
|
| 1812 | * fetcher.submit(
|
| 1813 | * { serialized: "values" },
|
| 1814 | * { method: "POST" }
|
| 1815 | * );
|
| 1816 | *
|
| 1817 | *
|
| 1818 | * fetcher.submit(
|
| 1819 | * {
|
| 1820 | * deeply: {
|
| 1821 | * nested: {
|
| 1822 | * json: "values",
|
| 1823 | * },
|
| 1824 | * },
|
| 1825 | * },
|
| 1826 | * {
|
| 1827 | * method: "POST",
|
| 1828 | * encType: "application/json",
|
| 1829 | * }
|
| 1830 | * );
|
| 1831 | * ```
|
| 1832 | */
|
| 1833 | submit: FetcherSubmitFunction;
|
| 1834 | };
|
| 1835 | /**
|
| 1836 | * Useful for creating complex, dynamic user interfaces that require multiple,
|
| 1837 | * concurrent data interactions without causing a navigation.
|
| 1838 | *
|
| 1839 | * Fetchers track their own, independent state and can be used to load data, submit
|
| 1840 | * forms, and generally interact with [`action`](../../start/framework/route-module#action)
|
| 1841 | * and [`loader`](../../start/framework/route-module#loader) functions.
|
| 1842 | *
|
| 1843 | * @example
|
| 1844 | * import { useFetcher } from "react-router"
|
| 1845 | *
|
| 1846 | * function SomeComponent() {
|
| 1847 | * let fetcher = useFetcher()
|
| 1848 | *
|
| 1849 | * // states are available on the fetcher
|
| 1850 | * fetcher.state // "idle" | "loading" | "submitting"
|
| 1851 | * fetcher.data // the data returned from the action or loader
|
| 1852 | *
|
| 1853 | * // render a form
|
| 1854 | * <fetcher.Form method="post" />
|
| 1855 | *
|
| 1856 | * // load data
|
| 1857 | * fetcher.load("/some/route")
|
| 1858 | *
|
| 1859 | * // submit data
|
| 1860 | * fetcher.submit(someFormRef, { method: "post" })
|
| 1861 | * fetcher.submit(someData, {
|
| 1862 | * method: "post",
|
| 1863 | * encType: "application/json"
|
| 1864 | * })
|
| 1865 | *
|
| 1866 | * // reset fetcher
|
| 1867 | * fetcher.reset()
|
| 1868 | * }
|
| 1869 | *
|
| 1870 | * @public
|
| 1871 | * @category Hooks
|
| 1872 | * @mode framework
|
| 1873 | * @mode data
|
| 1874 | * @param options Options
|
| 1875 | * @param options.key A unique key to identify the fetcher.
|
| 1876 | *
|
| 1877 | *
|
| 1878 | * By default, `useFetcher` generates a unique fetcher scoped to that component.
|
| 1879 | * If you want to identify a fetcher with your own key such that you can access
|
| 1880 | * it from elsewhere in your app, you can do that with the `key` option:
|
| 1881 | *
|
| 1882 | * ```tsx
|
| 1883 | * function SomeComp() {
|
| 1884 | * let fetcher = useFetcher({ key: "my-key" })
|
| 1885 | *
|
| 1886 | * }
|
| 1887 | *
|
| 1888 | *
|
| 1889 | * function AnotherComp() {
|
| 1890 | *
|
| 1891 | * let fetcher = useFetcher({ key: "my-key" });
|
| 1892 | *
|
| 1893 | * }
|
| 1894 | * ```
|
| 1895 | * @returns A {@link FetcherWithComponents} object that contains the fetcher's state, data, and components for submitting forms and loading data.
|
| 1896 | */
|
| 1897 | declare function useFetcher<T = any>({
|
| 1898 | key
|
| 1899 | }?: {
|
| 1900 | key?: string;
|
| 1901 | }): FetcherWithComponents<SerializeFrom<T>>;
|
| 1902 | /**
|
| 1903 | * Returns an array of all in-flight {@link Fetcher}s. This is useful for components
|
| 1904 | * throughout the app that didn't create the fetchers but want to use their submissions
|
| 1905 | * to participate in optimistic UI.
|
| 1906 | *
|
| 1907 | * @example
|
| 1908 | * import { useFetchers } from "react-router";
|
| 1909 | *
|
| 1910 | * function SomeComponent() {
|
| 1911 | * const fetchers = useFetchers();
|
| 1912 | * fetchers[0].formData; // FormData
|
| 1913 | * fetchers[0].state; // etc.
|
| 1914 | * // ...
|
| 1915 | * }
|
| 1916 | *
|
| 1917 | * @public
|
| 1918 | * @category Hooks
|
| 1919 | * @mode framework
|
| 1920 | * @mode data
|
| 1921 | * @returns An array of all in-flight {@link Fetcher}s, each with a unique `key`
|
| 1922 | * property.
|
| 1923 | */
|
| 1924 | declare function useFetchers(): (Fetcher & {
|
| 1925 | key: string;
|
| 1926 | })[];
|
| 1927 | /**
|
| 1928 | * When rendered inside a {@link RouterProvider}, will restore scroll positions
|
| 1929 | * on navigations
|
| 1930 | *
|
| 1931 | * <!--
|
| 1932 | * Not marked `@public` because we only export as UNSAFE_ and therefore we don't
|
| 1933 | * maintain an .md file for this hook
|
| 1934 | * -->
|
| 1935 | *
|
| 1936 | * @name UNSAFE_useScrollRestoration
|
| 1937 | * @category Hooks
|
| 1938 | * @mode framework
|
| 1939 | * @mode data
|
| 1940 | * @param options Options
|
| 1941 | * @param options.getKey A function that returns a key to use for scroll restoration.
|
| 1942 | * This is useful for custom scroll restoration logic, such as using only the pathname
|
| 1943 | * so that subsequent navigations to prior paths will restore the scroll. Defaults
|
| 1944 | * to `location.key`.
|
| 1945 | * @param options.storageKey The key to use for storing scroll positions in
|
| 1946 | * `sessionStorage`. Defaults to `"react-router-scroll-positions"`.
|
| 1947 | * @returns {void}
|
| 1948 | */
|
| 1949 | declare function useScrollRestoration({
|
| 1950 | getKey,
|
| 1951 | storageKey
|
| 1952 | }?: {
|
| 1953 | getKey?: GetScrollRestorationKeyFunction;
|
| 1954 | storageKey?: string;
|
| 1955 | }): void;
|
| 1956 | /**
|
| 1957 | * Set up a callback to be fired on [Window's `beforeunload` event](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event).
|
| 1958 | *
|
| 1959 | * @public
|
| 1960 | * @category Hooks
|
| 1961 | * @param callback The callback to be called when the [`beforeunload` event](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event)
|
| 1962 | * is fired.
|
| 1963 | * @param options Options
|
| 1964 | * @param options.capture If `true`, the event will be captured during the capture
|
| 1965 | * phase. Defaults to `false`.
|
| 1966 | * @returns {void}
|
| 1967 | */
|
| 1968 | declare function useBeforeUnload(callback: (event: BeforeUnloadEvent) => any, options?: {
|
| 1969 | capture?: boolean;
|
| 1970 | }): void;
|
| 1971 | /**
|
| 1972 | * Wrapper around {@link useBlocker} to show a [`window.confirm`](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm)
|
| 1973 | * prompt to users instead of building a custom UI with {@link useBlocker}.
|
| 1974 | *
|
| 1975 | * The `unstable_` flag will not be removed because this technique has a lot of
|
| 1976 | * rough edges and behaves very differently (and incorrectly sometimes) across
|
| 1977 | * browsers if users click addition back/forward navigations while the
|
| 1978 | * confirmation is open. Use at your own risk.
|
| 1979 | *
|
| 1980 | * @example
|
| 1981 | * function ImportantForm() {
|
| 1982 | * let [value, setValue] = React.useState("");
|
| 1983 | *
|
| 1984 | * // Block navigating elsewhere when data has been entered into the input
|
| 1985 | * unstable_usePrompt({
|
| 1986 | * message: "Are you sure?",
|
| 1987 | * when: ({ currentLocation, nextLocation }) =>
|
| 1988 | * value !== "" &&
|
| 1989 | * currentLocation.pathname !== nextLocation.pathname,
|
| 1990 | * });
|
| 1991 | *
|
| 1992 | * return (
|
| 1993 | * <Form method="post">
|
| 1994 | * <label>
|
| 1995 | * Enter some important data:
|
| 1996 | * <input
|
| 1997 | * name="data"
|
| 1998 | * value={value}
|
| 1999 | * onChange={(e) => setValue(e.target.value)}
|
| 2000 | * />
|
| 2001 | * </label>
|
| 2002 | * <button type="submit">Save</button>
|
| 2003 | * </Form>
|
| 2004 | * );
|
| 2005 | * }
|
| 2006 | *
|
| 2007 | * @name unstable_usePrompt
|
| 2008 | * @public
|
| 2009 | * @category Hooks
|
| 2010 | * @mode framework
|
| 2011 | * @mode data
|
| 2012 | * @param options Options
|
| 2013 | * @param options.message The message to show in the confirmation dialog.
|
| 2014 | * @param options.when A boolean or a function that returns a boolean indicating
|
| 2015 | * whether to block the navigation. If a function is provided, it will receive an
|
| 2016 | * object with `currentLocation` and `nextLocation` properties.
|
| 2017 | * @returns {void}
|
| 2018 | */
|
| 2019 | declare function usePrompt({
|
| 2020 | when,
|
| 2021 | message
|
| 2022 | }: {
|
| 2023 | when: boolean | BlockerFunction;
|
| 2024 | message: string;
|
| 2025 | }): void;
|
| 2026 | /**
|
| 2027 | * This hook returns `true` when there is an active [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)
|
| 2028 | * and the specified location matches either side of the navigation (the URL you are
|
| 2029 | * navigating **to** or the URL you are navigating **from**). This can be used to apply finer-grained styles to
|
| 2030 | * elements to further customize the view transition. This requires that view
|
| 2031 | * transitions have been enabled for the given navigation via {@link LinkProps.viewTransition}
|
| 2032 | * (or the `Form`, `submit`, or `navigate` call)
|
| 2033 | *
|
| 2034 | * @public
|
| 2035 | * @category Hooks
|
| 2036 | * @mode framework
|
| 2037 | * @mode data
|
| 2038 | * @param to The {@link To} location to compare against the active transition's current
|
| 2039 | * and next URLs.
|
| 2040 | * @param options Options
|
| 2041 | * @param options.relative The relative routing type to use when resolving the
|
| 2042 | * `to` location, defaults to `"route"`. See {@link RelativeRoutingType} for
|
| 2043 | * more details.
|
| 2044 | * @returns `true` if there is an active [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)
|
| 2045 | * and the resolved path matches the transition's destination or source pathname, otherwise `false`.
|
| 2046 | */
|
| 2047 | declare function useViewTransitionState(to: To, {
|
| 2048 | relative
|
| 2049 | }?: {
|
| 2050 | relative?: RelativeRoutingType;
|
| 2051 | }): boolean;
|
| 2052 | //#endregion
|
| 2053 | export { BrowserRouter, BrowserRouterProps, DOMRouterOpts, FetcherFormProps, FetcherSubmitFunction, FetcherWithComponents, Form, FormProps, HashRouter, HashRouterProps, HistoryRouter, HistoryRouterProps, Link, LinkProps, NavLink, NavLinkProps, NavLinkRenderProps, ScrollRestoration, ScrollRestorationProps, SetURLSearchParams, SubmitFunction, createBrowserRouter, createHashRouter, useBeforeUnload, useFetcher, useFetchers, useFormAction, useLinkClickHandler, usePrompt, useScrollRestoration, useSearchParams, useSubmit, useViewTransitionState }; |
| \ | No newline at end of file |