-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Link with forwardRef component not working #9784
Comments
I think you'll want to try to reproduce this while using a Next.js codesandbox and by running your app with Here is an empty Next.js codesandbox you could use. |
|
This appears to be working. Code taken from this issue (#8425) |
@jamesmosier can you check this: https://github.com/rahul3103/testLink I am using create next app. And link is also not working here. |
View the codesandbox code i sent. const MyButton = React.forwardRef(({ href, onClick }, ref) => (
<a href={href} ref={ref} onClick={onClick}>
Click Me
</a>
)); you have to pass And you have to have a page inside |
There is no way around this. You have to use |
Yeah I know, I have to use |
Sorry, i'm not understanding. From my perspective, this code should work perfectly: // need to add `onClick={onClick}` NOT onClick={console.log} as you have
const MyButton = React.forwardRef(({ onClick, href }, ref) => (
<a href={href} onClick={onClick} ref={ref}>
Click Me
</a>
));
const Home = () => (
<Link passHref href="/about">
<MyButton />
</Link>
)
export default Home |
Yeah, the above code works perfectly but I don't want my page to reload on the click of link. That's why I added console to show you how events are getting consoled but the page is also getting reloaded on client side on change of URL. console is just logging the events which is getting triggered onclick of link. But, onclicking the link the console comes and go. Which means the page reloaded |
In order for the page to NOT reload, you CANNOT have It NEEDS to be Aside from that, try asking on spectrum or stackoverflow as this is not an issue with Next.js itself. |
This I am using but my page rerenders |
As mentioned by @jamesmosier the props like I'm going to close this as it doesn't seem to be an issue with Next.js and we also already have tests covering this here |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
Link with forward ref doesn't work anymore. If I pass
passHref
than it passes the href but the page gets reloaded.To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
https://codesandbox.io/s/nextjs-wtnzg
https://github.com/rahul3103/testLink
Expected behavior
I expected url to be seen in the bottom left on hover but it was not there, than I inspected
a
and there was nohref
. But, I was getting theonClick
event. Than, I addedpassHref
toLink
. After thathref
was there butonClick
the whole page was getting re rendered.System information
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: