-
-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[core] Use router specific Link components #4661
base: master
Are you sure you want to change the base?
Changes from 1 commit
6b85584
31f2bdf
dd024a8
4f57c42
c41f976
5d4ca97
2b2bd2b
c9a92e1
c6fee40
57d3d22
ecbf7e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import * as React from 'react'; | ||
import Link from 'next/link'; | ||
import { asArray } from '@toolpad/utils/collections'; | ||
import { useRouter } from 'next/router'; | ||
import { AppProvider } from '../AppProvider'; | ||
|
@@ -41,6 +42,7 @@ export function NextAppProviderPages(props: AppProviderProps) { | |
pathname, | ||
searchParams, | ||
navigate, | ||
Link, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this needs to handle the |
||
}), | ||
[navigate, pathname, searchParams], | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,11 @@ export const Link = React.forwardRef(function Link( | |
}; | ||
}, [routerContext, onClick, history]); | ||
|
||
return ( | ||
return routerContext?.Link && href ? ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When there is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, the Link component that is exported from this module should have the same signature as the one in the export const Link = React.forwardRef(function Link(
props: LinkProps,
ref: React.ForwardedRef<HTMLAnchorElement>,
) {
const routerContext = React.useContext(RouterContext);
const LinkComponent = routerContext?.Link ?? DefaultLink
return <LinkComponent ref={ref} {...props} />
}) this to avoid unnecessary callback creation and other render logic running in the default link. |
||
<routerContext.Link href={href} to={href} {...rest} onClick={onClick}> | ||
{children} | ||
</routerContext.Link> | ||
) : ( | ||
<a ref={ref} href={href} {...rest} onClick={handleLinkClick}> | ||
{children} | ||
</a> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems incorrect because:
We need to define an abstract LinkProps type ourselves, and then make sure in the routeradapter to map the concrete implementation to the abstract properties.