diff --git a/__tests__/__snapshots__/hooks.test.tsx.snap b/__tests__/__snapshots__/hooks.test.tsx.snap index ff047dd..85868e3 100644 --- a/__tests__/__snapshots__/hooks.test.tsx.snap +++ b/__tests__/__snapshots__/hooks.test.tsx.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`useMatch 1`] = ` +exports[`Router preset pathname 1`] = `
     {
diff --git a/__tests__/hooks.test.tsx b/__tests__/hooks.test.tsx
index 4305d19..ea119b8 100644
--- a/__tests__/hooks.test.tsx
+++ b/__tests__/hooks.test.tsx
@@ -13,7 +13,7 @@ const EffCee = (_: ExtractRouteParams) => {
   return 
{JSON.stringify(match, null, 2)}
; }; -test('useMatch', async () => { +test('Router preset pathname', async () => { const { asFragment } = render( ; - export const Routes = forwardRef( ({ children }, forwardedRef) => { const [url] = useLocation(); @@ -24,16 +21,16 @@ export const Routes = forwardRef( const { pathname } = url; const [child, matchResult] = useMemo((): [ - ReactElement | null, + ReactElement | null, MatchResult | false, ] => { let match: MatchResult | false = false; - let matchChild: ReactElement | null = null; + let matchChild: ReactElement | null = null; flattenFragments(children) .filter( - (c): c is ReactElement => - isValidElement(c) && + (c): c is ReactElement => + isValidElement(c) && // supports native routes, and also custom route components (c.type === Route || 'path' in c.props), ) diff --git a/lib/components/Link.tsx b/lib/components/Link.tsx index 0438cdc..13c1d92 100644 --- a/lib/components/Link.tsx +++ b/lib/components/Link.tsx @@ -82,7 +82,7 @@ export const Link = forwardRef< const newProps: LinkChildProps = { ...props, href: isSameOrigin ? urlRhs(destAsUrl) : href.toString(), - ...(!hasNav && { onClick: handleClick }), + onClick: hasNav ? onClick : handleClick, ...(!isSameOrigin && { rel: 'no-opener noreferrer' }), ref, }; diff --git a/lib/matcher.ts b/lib/matcher.ts index 48739de..8c713cd 100644 --- a/lib/matcher.ts +++ b/lib/matcher.ts @@ -1,8 +1,12 @@ import type { ReactElement } from 'react'; import { parse } from 'regexparam'; import { pathCache } from './path-cache.js'; -import type { RouteComponent } from './Routes.js'; -import type { ExtractRouteParams, Params, RoutingProps } from './types.js'; +import type { + ExtractRouteParams, + Params, + RouteComponentProps, + RoutingProps, +} from './types.js'; export type Match = | MatchResult> @@ -15,7 +19,7 @@ export interface MatchResult

{ } export type Matcher = ( - component: ReactElement, + component: ReactElement, pathname: string, ) => Match | false; diff --git a/lib/path-cache.ts b/lib/path-cache.ts index 91271cf..568c637 100644 --- a/lib/path-cache.ts +++ b/lib/path-cache.ts @@ -1,6 +1,6 @@ import type { RoutingProps } from './types.js'; -export function pathCache

, T>( +export function pathCache

( map: WeakMap, props: P, builder: (props: P) => T, diff --git a/lib/types.ts b/lib/types.ts index 06683a5..031f5db 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -1,6 +1,7 @@ import type { FC, ReactNode } from 'react'; -type Path = string | undefined; +type Path = string; +type MaybePath = Path | undefined; export type Params = Record; @@ -35,12 +36,12 @@ export type ExtractRouteParams = string extends PathType : // eslint-disable-next-line @typescript-eslint/ban-types {}; -export interface RoutingProps { +export interface RoutingProps { path: TPath; wildcard?: boolean | undefined; } -export type RouteComponentProps = +export type RouteComponentProps = | { children: ReactNode; // path?: never; diff --git a/package.json b/package.json index 50a4c45..de8d9be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@block65/mrr", - "version": "5.3.0", + "version": "6.0.0-rc1", "private": false, "license": "MIT", "sideEffects": false,