-
-
Notifications
You must be signed in to change notification settings - Fork 341
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 | ||||
---|---|---|---|---|---|---|
|
@@ -5,15 +5,17 @@ import { RouterContext } from './context'; | |||||
* @ignore - internal component. | ||||||
*/ | ||||||
|
||||||
export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> { | ||||||
export interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, '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. No need to change this type. The router adapters are responsible for translating this to their concrete implementation. The goal is for us internally have only one standard way to create links, and the router adapter to translate this to a specific implementation. |
||||||
history?: 'auto' | 'push' | 'replace'; | ||||||
href: string; | ||||||
to: string; | ||||||
} | ||||||
|
||||||
export const Link = React.forwardRef(function Link( | ||||||
props: LinkProps, | ||||||
ref: React.ForwardedRef<HTMLAnchorElement>, | ||||||
) { | ||||||
const { children, href, onClick, history, ...rest } = props; | ||||||
const { children, href, onClick, history, to, ...rest } = props; | ||||||
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.
Suggested change
We're just passing |
||||||
const routerContext = React.useContext(RouterContext); | ||||||
|
||||||
const handleLinkClick = React.useMemo(() => { | ||||||
|
@@ -29,7 +31,7 @@ export const Link = React.forwardRef(function Link( | |||||
}, [routerContext, onClick, history]); | ||||||
|
||||||
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}> | ||||||
<routerContext.Link href={href} to={to} {...rest} onClick={onClick}> | ||||||
{children} | ||||||
</routerContext.Link> | ||||||
) : ( | ||||||
|
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.
I don't think we want to allow for say
'div'
or something