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

Allow Link components without pathname #3662

Closed
Phyks opened this issue Jul 22, 2016 · 3 comments
Closed

Allow Link components without pathname #3662

Phyks opened this issue Jul 22, 2016 · 3 comments

Comments

@Phyks
Copy link

Phyks commented Jul 22, 2016

Hi,

I have a feature request concerning <Link> API. My typical use case is that I want to have buttons to pass query parameters, but stay on the same page. Then, I was thinking of doing something like

<Link to={{ query: { page: 1 } }}

But it does not work because Link component expects to have a pathname value.

My problem is then that I have to do something like

<Link to={{ pathname: currentPath, query: { page: 1 } }}

but that I have to fetch the currentPath from somewhere. If I was in a Route component, I could just fetch this.props.location.pathname, but this is not my case, and I am in an included components, some levels deep.

I thought about using the context injection, but the injected object does not offer any possibility to retrieve current pathname apparently.

So, my feature request is to either allow a Link without pathname, and then defaults the pathname to the current pathname, or provide a way to access current pathname outside of props. Indeed, as of now, the only solution I could find is to pass the location props down to every component, which is quite verbose, especially since I only need it in a single component downwards.

Thanks!

@taion
Copy link
Contributor

taion commented Jul 22, 2016

You spread in the old location – { ...location, query: newQuery }. If we go ahead with #3657 it will be even easier.

We don't really want to do this at the level of <Link> like this directly because the object spread syntax is just as terse but gives you more direct control over how you build the new location.

@taion taion closed this as completed Jul 22, 2016
@Phyks
Copy link
Author

Phyks commented Jul 22, 2016

Ok for spreading the old location, but this means I must pass location as a prop down the component tree, no?

Sorry if I missed something :/

@taion
Copy link
Contributor

taion commented Jul 22, 2016

See #3657 for a proposal on sidestepping that requirement.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
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