Replies: 1 comment 2 replies
-
I have faced the same problem when building my personal website in Next.js App Router (even before Next.js 13 was released). I was trying to implement the similar And here I propose another solution: const [isPending, aProps] = useLink('/', { onClick() { /** extra on click handler should be put here */ } });
<a className={isPending && 'navigating'} {...aProps} /> Update For those who are interested, I've created a user-land https://foxact.skk.moe/use-next-link import { unstable_useNextLink as useNextLink } from 'foxact/use-next-link';
export default function Page() {
const [isPending, linkProps] = useNextLink('/about');
return (
<div>
{isPending && <div>Navigating...</div>}
<a className="link" {...linkProps}>
About
</a>
</div>
);
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
No response
Background
llamaindex is building a giant project using Next.js 14 with app dir, and the project is like this:
And its file structure
In layout.js
The link component will take a few seconds if each page is big, and I want to add a loading spinner beside the links like this:
I can only add
loading.js
on the same level, but this is not a good approach and cannot control the granularity UIhttps://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming
Proposal
startTransition
andisPending
, like addingprops.startTransition
API or similar.next.js/packages/next/src/client/link.tsx
Line 238 in 498f342
For example
This is correct because it is a sync function.
useRouterPending
or somethingBut this would violate the rule of React, I think?
useLinkStatus
hooks likereact-dom/client
Workaround
Beta Was this translation helpful? Give feedback.
All reactions