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

Feature Request: <Link component> #5437

Closed
LazyElephant opened this issue Aug 17, 2017 · 4 comments
Closed

Feature Request: <Link component> #5437

LazyElephant opened this issue Aug 17, 2017 · 4 comments

Comments

@LazyElephant
Copy link

Why

TLDR: This will create a consistent interface in both react-router-dom and react-router-native, allowing code reuse.

I just started building an app using React Native/React Native Web with the goal of using 99.9% of the same code. I decided to use React Router with it since both the web and native versions offer the same library components (mostly). This allows me to alias react-router-native to react-router-dom with webpack, resulting in the correct library being called based on the platform.

By adding the 'component' prop to the Link component in react-router-dom, cross platform components can be rendered instead of an anchor tag.

Example Usage

<Link
     to="/about"
     component={TouchableHighlight}
     underlayColor='#f0f4f7'
     style={styles.navItem}>
        <Text>About</Text>
</Link>

I already made this change with tests in a forked repo here and the proof of concept project I'm working on is here. If you would like to make this change, I can make a pull request any time.

@pshrmn
Copy link
Contributor

pshrmn commented Aug 17, 2017

This has been discussed a number of times and just isn't going to happen. Using anything besides an anchor opens up accessibility issues that React Router does not want to expose users to.

If you want this behavior, you can easily clone Link.js, make the modifications to allow for custom components, and include that in your project. You could even open source and release that as a package. As I said, there are other people that want this behavior, but it just isn't something that React Router wants to encourage.

@pshrmn pshrmn closed this as completed Aug 17, 2017
@mjackson mjackson reopened this Oct 11, 2018
@mjackson
Copy link
Member

Thanks for the offer of help here, @LazyElephant. I'd like to figure out a way we can help you with this.

In the past we had a contributor who was very adamant that we always render a <a> with react-router-dom's <Link> component (see e.g. #4625), but your use case is really compelling. Would you still be open to helping us out with a PR?

@mjackson mjackson changed the title Feature Request: add a 'component' prop to <Link> Feature Request: <Link component> Oct 11, 2018
@mjackson mjackson added this to the 4.4 milestone Nov 1, 2018
mjackson added a commit that referenced this issue Nov 7, 2018
mjackson added a commit that referenced this issue Nov 8, 2018
@krainboltgreene
Copy link

@mjackson mjackson modified the milestones: 4.4, 4.5 Mar 15, 2019
@mjackson mjackson removed this from the 5.1 milestone Mar 26, 2019
timdorr pushed a commit that referenced this issue Jun 12, 2019
timdorr pushed a commit that referenced this issue Jun 13, 2019
@timdorr timdorr closed this as completed Jul 17, 2019
@mjackson mjackson mentioned this issue Aug 26, 2019
23 tasks
@lock lock bot locked as resolved and limited conversation to collaborators Sep 15, 2019
@mjackson
Copy link
Member

This shipped today in 5.1.0

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

5 participants