context.d.ts 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import * as React from "react";
  2. import type { AgnosticRouteMatch, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, History, Location, Router, StaticHandlerContext, To, TrackedPromise } from "@remix-run/router";
  3. import type { Action as NavigationType } from "@remix-run/router";
  4. export interface IndexRouteObject {
  5. caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
  6. path?: AgnosticIndexRouteObject["path"];
  7. id?: AgnosticIndexRouteObject["id"];
  8. loader?: AgnosticIndexRouteObject["loader"];
  9. action?: AgnosticIndexRouteObject["action"];
  10. hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
  11. shouldRevalidate?: AgnosticIndexRouteObject["shouldRevalidate"];
  12. handle?: AgnosticIndexRouteObject["handle"];
  13. index: true;
  14. children?: undefined;
  15. element?: React.ReactNode | null;
  16. errorElement?: React.ReactNode | null;
  17. }
  18. export interface NonIndexRouteObject {
  19. caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
  20. path?: AgnosticNonIndexRouteObject["path"];
  21. id?: AgnosticNonIndexRouteObject["id"];
  22. loader?: AgnosticNonIndexRouteObject["loader"];
  23. action?: AgnosticNonIndexRouteObject["action"];
  24. hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
  25. shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"];
  26. handle?: AgnosticNonIndexRouteObject["handle"];
  27. index?: false;
  28. children?: RouteObject[];
  29. element?: React.ReactNode | null;
  30. errorElement?: React.ReactNode | null;
  31. }
  32. export declare type RouteObject = IndexRouteObject | NonIndexRouteObject;
  33. export declare type DataRouteObject = RouteObject & {
  34. children?: DataRouteObject[];
  35. id: string;
  36. };
  37. export interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> extends AgnosticRouteMatch<ParamKey, RouteObjectType> {
  38. }
  39. export interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
  40. }
  41. export interface DataRouterContextObject extends NavigationContextObject {
  42. router: Router;
  43. staticContext?: StaticHandlerContext;
  44. }
  45. export declare const DataRouterContext: React.Context<DataRouterContextObject | null>;
  46. export declare const DataRouterStateContext: React.Context<import("@remix-run/router").RouterState | null>;
  47. export declare const AwaitContext: React.Context<TrackedPromise | null>;
  48. export declare type RelativeRoutingType = "route" | "path";
  49. export interface NavigateOptions {
  50. replace?: boolean;
  51. state?: any;
  52. preventScrollReset?: boolean;
  53. relative?: RelativeRoutingType;
  54. }
  55. /**
  56. * A Navigator is a "location changer"; it's how you get to different locations.
  57. *
  58. * Every history instance conforms to the Navigator interface, but the
  59. * distinction is useful primarily when it comes to the low-level <Router> API
  60. * where both the location and a navigator must be provided separately in order
  61. * to avoid "tearing" that may occur in a suspense-enabled app if the action
  62. * and/or location were to be read directly from the history instance.
  63. */
  64. export interface Navigator {
  65. createHref: History["createHref"];
  66. encodeLocation?: History["encodeLocation"];
  67. go: History["go"];
  68. push(to: To, state?: any, opts?: NavigateOptions): void;
  69. replace(to: To, state?: any, opts?: NavigateOptions): void;
  70. }
  71. interface NavigationContextObject {
  72. basename: string;
  73. navigator: Navigator;
  74. static: boolean;
  75. }
  76. export declare const NavigationContext: React.Context<NavigationContextObject>;
  77. interface LocationContextObject {
  78. location: Location;
  79. navigationType: NavigationType;
  80. }
  81. export declare const LocationContext: React.Context<LocationContextObject>;
  82. export interface RouteContextObject {
  83. outlet: React.ReactElement | null;
  84. matches: RouteMatch[];
  85. }
  86. export declare const RouteContext: React.Context<RouteContextObject>;
  87. export declare const RouteErrorContext: React.Context<any>;
  88. export {};