Skip to content

Commit

Permalink
Refactored outlets
Browse files Browse the repository at this point in the history
  • Loading branch information
smikhalevski committed Jul 12, 2024
1 parent 2e3014b commit 1789425
Show file tree
Hide file tree
Showing 27 changed files with 861 additions and 665 deletions.
4 changes: 3 additions & 1 deletion src/main/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { HTMLAttributes, MouseEvent, ReactElement, useEffect } from 'react';
import { useNavigation } from './hooks';
import { LocationOptions, To } from './types';
import { useNavigation } from './useNavigation';

/**
* Props of the {@link Link} component.
Expand Down Expand Up @@ -62,3 +62,5 @@ export function Link(props: LinkProps): ReactElement {
/>
);
}

Link.displayName = 'Link';
24 changes: 21 additions & 3 deletions src/main/Navigation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { toLocation } from './utils';
import { matchRoutes } from './matchRoutes';
import { Router, RouterProps } from './Router';
import { To } from './types';
import { toLocation } from './utils';

// export interface RouteSnapshot<Params, Data> {
// params: Params;
// data: Data;
// isLoading: boolean;
// }

/**
* Provides components a way to trigger router navigation.
Expand All @@ -15,6 +21,18 @@ export class Navigation {
*/
constructor(private _router: Router<any>) {}

// get isLoading(): boolean {
// return false;
// }
//
// isRendered(route: Route): boolean {
// return false;
// }
//
// get<Params extends object | void, Data>(route: Route<any, Params, Data>): RouteSnapshot<Params, Data> {
// return null!;
// }

/**
* Triggers {@link RouterProps.onPush} with the requested location.
*
Expand Down Expand Up @@ -49,15 +67,15 @@ export class Navigation {
*/
prefetch(to: To): boolean {
const location = toLocation(to);
const { routes, context } = this._router.props as RouterProps<unknown>;
const { routes, context } = this._router.props;

const routeMatches = matchRoutes(location.pathname, location.searchParams, routes);

if (routeMatches === null) {
return false;
}
for (const routeMatch of routeMatches) {
routeMatch.route.prefetch(routeMatch.params, context);
routeMatch.route.loader(routeMatch.params, context);
}
return true;
}
Expand Down
Loading

0 comments on commit 1789425

Please sign in to comment.