context.d.ts 4.4 KB

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