mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
Core: hotfix Tanstack Router usePathname
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-core': patch
|
||||
---
|
||||
|
||||
hotfix Tanstack Router `usePathname` inconsistency due to `useMatch` on layout.
|
||||
@@ -1,9 +1,14 @@
|
||||
import { type ReactNode, useMemo } from 'react';
|
||||
import { type ReactNode, useRef, useMemo } from 'react';
|
||||
import { type Framework, FrameworkProvider } from '@/framework/index';
|
||||
import { useParams, Link, useRouter, useMatch } from '@tanstack/react-router';
|
||||
import {
|
||||
useParams,
|
||||
Link,
|
||||
useRouter,
|
||||
useRouterState,
|
||||
} from '@tanstack/react-router';
|
||||
|
||||
const framework: Framework = {
|
||||
Link({ href, prefetch, ...props }) {
|
||||
Link({ href, prefetch = true, ...props }) {
|
||||
return (
|
||||
<Link to={href} preload={prefetch ? 'intent' : false} {...props}>
|
||||
{props.children}
|
||||
@@ -11,7 +16,22 @@ const framework: Framework = {
|
||||
);
|
||||
},
|
||||
usePathname() {
|
||||
return useMatch({ strict: false, select: (s) => s.pathname });
|
||||
const { isLoading, pathname } = useRouterState({
|
||||
select: (state) => ({
|
||||
isLoading: state.isLoading,
|
||||
pathname: state.location.pathname,
|
||||
}),
|
||||
});
|
||||
|
||||
const activePathname = useRef(pathname);
|
||||
return useMemo(() => {
|
||||
if (isLoading) {
|
||||
return activePathname.current;
|
||||
}
|
||||
|
||||
activePathname.current = pathname;
|
||||
return pathname;
|
||||
}, [isLoading, pathname]);
|
||||
},
|
||||
useRouter() {
|
||||
const router = useRouter();
|
||||
|
||||
@@ -3,7 +3,7 @@ import { type ComponentProps, Fragment, useState } from 'react';
|
||||
import { cva } from 'class-variance-authority';
|
||||
import Link from 'fumadocs-core/link';
|
||||
import { cn } from '@/utils/cn';
|
||||
import { BaseLinkItem, LinkItemType } from '@/layouts/shared';
|
||||
import { BaseLinkItem, type LinkItemType } from '@/layouts/shared';
|
||||
import {
|
||||
NavigationMenu,
|
||||
NavigationMenuContent,
|
||||
|
||||
Reference in New Issue
Block a user