Skip to content
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

Adding a click handler with addEventListener to an anchor inside a Link breaks Link #5247

Closed
trusktr opened this issue Sep 21, 2018 · 6 comments

Comments

@trusktr
Copy link

trusktr commented Sep 21, 2018

Bug report

Describe the bug

I want to

If some React component is like the following,

export default () => ({
  <Link>
    <a href="/foo" className="foo"></a>
  </Link>
})

then in some other file I want to do

document.querySelector('a.foo')
  .addEventListener('click', () => doSomething())

but this breaks the Link behavior, and causes the page to do a full refresh instead of changing routes.

I do not have access to (it is very complicated to supply) onClick handler inside the other component. I need to do it simply, with the imperative DOM API.

Expected behavior

How do we add a click handler imperatively without breaking the Link?

System information

  • OS: macOS
  • Version of Next.js: 6.1.1
@timneutkens
Copy link
Member

Can you create a minimal repository for this, I wonder if we should even support this, I'm guessing it's just a React vs DOM api thing instead of a real issue with Next.js, but I can have a look.

@trusktr
Copy link
Author

trusktr commented Sep 21, 2018

Do you happen to have a CodeSandbox or StackBlitz starter? Those are easier to work with. It's worth making one, and leave the link in the issue template for people to fork.

@timneutkens
Copy link
Member

timneutkens commented Sep 21, 2018

They don't support Next.js, you could try repl.it, but you could also push up a repository like everyone else 😄

@trusktr
Copy link
Author

trusktr commented Sep 21, 2018

Heeeeeeeey, look! https://repl.it/site/languages/nextjs

@timneutkens
Copy link
Member

That's just the landing page haha, I knew they support Next.js, hence why I mentioned it.

@trusktr
Copy link
Author

trusktr commented Sep 22, 2018

Cool. I'll use that to make a repro when I circle back.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants