app-router-context.d.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React from 'react';
  2. import type { FocusAndScrollRef } from '../../client/components/reducer';
  3. import type { FlightRouterState, FlightData } from '../../server/app-render';
  4. export declare type ChildSegmentMap = Map<string, CacheNode>;
  5. /**
  6. * Cache node used in app-router / layout-router.
  7. */
  8. export declare type CacheNode = {
  9. /**
  10. * In-flight request for this node.
  11. */
  12. data: ReturnType<typeof import('../../client/components/app-router.client').fetchServerResponse> | null;
  13. /**
  14. * React Component for this node.
  15. */
  16. subTreeData: React.ReactNode | null;
  17. /**
  18. * Child parallel routes.
  19. */
  20. parallelRoutes: Map<string, ChildSegmentMap>;
  21. };
  22. interface NavigateOptions {
  23. forceOptimisticNavigation?: boolean;
  24. }
  25. export interface AppRouterInstance {
  26. /**
  27. * Reload the current page. Fetches new data from the server.
  28. */
  29. reload(): void;
  30. /**
  31. * Hard navigate to the provided href. Fetches new data from the server.
  32. * Pushes a new history entry.
  33. */
  34. push(href: string, options: NavigateOptions): void;
  35. /**
  36. * Hard navigate to the provided href. Does not fetch data from the server if it was already fetched.
  37. * Replaces the current history entry.
  38. */
  39. replace(href: string, options: NavigateOptions): void;
  40. /**
  41. * Soft prefetch the provided href. Does not fetch data from the server if it was already fetched.
  42. */
  43. prefetch(href: string): void;
  44. }
  45. export declare const AppRouterContext: React.Context<AppRouterInstance>;
  46. export declare const LayoutRouterContext: React.Context<{
  47. childNodes: CacheNode['parallelRoutes'];
  48. tree: FlightRouterState;
  49. url: string;
  50. }>;
  51. export declare const GlobalLayoutRouterContext: React.Context<{
  52. tree: FlightRouterState;
  53. changeByServerResponse: (previousTree: FlightRouterState, flightData: FlightData) => void;
  54. focusAndScrollRef: FocusAndScrollRef;
  55. }>;
  56. export declare const TemplateContext: React.Context<React.ReactNode>;
  57. export {};