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

Pass className into <Link>...</Link> #588

Closed
matthewmueller opened this issue Dec 31, 2016 · 10 comments
Closed

Pass className into <Link>...</Link> #588

matthewmueller opened this issue Dec 31, 2016 · 10 comments

Comments

@matthewmueller
Copy link
Contributor

matthewmueller commented Dec 31, 2016

Would probably be good to pass entire props in actually

<a {...props}>...</a>
@matthewmueller
Copy link
Contributor Author

oh weird, seems like it does this. not sure what's going on then 😅

@matthewmueller
Copy link
Contributor Author

matthewmueller commented Jan 15, 2017

Actually, I'm still running into issues with this on latest beta. Doesn't seem to work properly:

import Link from 'next/link'
<Link href='/' className='link'>hi</Link>

Can someone double-check this?

@nkzawa
Copy link
Contributor

nkzawa commented Jan 15, 2017

@matthewmueller Link component accepts only href and as props. You can set className to a.

<Link><a className="link">hi</Link>

@matthewmueller
Copy link
Contributor Author

matthewmueller commented Jan 15, 2017

Ahh okay, so would this:

<Link as="/hello"><a href="/hi" className="link">hi</a></Link>

resolve to: <a href="/hi" className="link">hi</a> with the <Link /> logic in place?

@rauchg
Copy link
Member

rauchg commented Jan 15, 2017

I'm pretty sure we should deprecate <Link>text</Link> for 2.0. (PR welcome)
It should just be HOC so that we can statically access (and decorate) children with styled-jsx, but also useful for css-in-js in general

@rauchg
Copy link
Member

rauchg commented Jan 15, 2017

Also @matthewmueller that /hi would only apply to things like "command+click" on the link (and I'm not 100% sure if we'll overwrite it anyways, but we probably shouldn't). If what you want is to use a certain page, but decorate it differently in navigation, you want <Link as>

@impronunciable
Copy link
Contributor

As @rauchg stated we are deprecating <Link>text</Link> so the className should be applied always to the <a> tag

@matthewmueller
Copy link
Contributor Author

I'm sorry but I'm still a little confused about this. Is the idea that you'd never add an href the the inside <a> tag? Or are there cases where you'd want to?

@rauchg
Copy link
Member

rauchg commented Jan 17, 2017

We do pass down the href from <Link> to the case where you have an <a> child. What we're deprecating is inserting an <a> automagically.

You should be able to <Link><img /></Link> and no <a> is created, for example

@matthewmueller
Copy link
Contributor Author

Got it – thanks!

@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
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

4 participants