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 to> to be a function #3657

Closed
taion opened this issue Jul 21, 2016 · 14 comments
Closed

Allow <Link to> to be a function #3657

taion opened this issue Jul 21, 2016 · 14 comments
Labels

Comments

@taion
Copy link
Contributor

taion commented Jul 21, 2016

Maybe a little QoL, thing... it'd let people do e.g.

<Link to={location => ({ ...location, query: newQuery })>

without having to worry about having location on context or wrapping the <Link>'s parent with withRouter.

@taion taion added the feature label Jul 21, 2016
@avocadowastaken
Copy link

avocadowastaken commented Jul 21, 2016

This is really good feature! But what about push and replace?

@smashercosmo
Copy link
Contributor

This is awesome

@smashercosmo
Copy link
Contributor

smashercosmo commented Jul 21, 2016

I would like to propose also a possibility to provide a function to set isActive flag. Something like

<Link to="/hello" isActive={location => location.pathname === '/hello'} activeClassName="active">

@smashercosmo
Copy link
Contributor

@jodo4x Where do you get pathname from?

@smashercosmo
Copy link
Contributor

@jodo4x yes, but if your component is deeply nested you need to pass location through the components tree.

Well this issue is not suited for this discussion. I'll open a separate one.

@timdorr
Copy link
Member

timdorr commented Jul 26, 2016

Added in #3669

@timdorr timdorr closed this as completed Jul 26, 2016
@taion
Copy link
Contributor Author

taion commented Jul 30, 2016

Hmm, I wonder if these functions should take e.g. { location, params } instead of just location as the arg.

@eldh
Copy link

eldh commented Jul 31, 2016

I think { location, params } would be great.

@taion taion reopened this Jul 31, 2016
@taion
Copy link
Contributor Author

taion commented Jul 31, 2016

@eldh Thanks for your feedback! How would you use params? Would it be to essentially build a relative link?

@taion
Copy link
Contributor Author

taion commented Jul 31, 2016

The reason I ask is because I can think of a few places where I could use params, but in all those it's only to work around the lack of relative links. I don't want to complicate the API here just to work around a missing feature elsewhere – would rather add that missing feature.

@eldh
Copy link

eldh commented Aug 1, 2016

Yeah, that would be a common case. We have some places where we do filtering in such a way that it would be a nice addition. Not sure, maybe relative links could solve that too.

@taion
Copy link
Contributor Author

taion commented Aug 1, 2016

@eldh Can you clarify regarding the filtering use case a bit? Just trying to understand use cases here.

I'm really torn here because (location: Location) => LocationDescriptor just feels like a cleaner and more symmetric API, and lets the user be a bit terser when writing things like

({ query, ...location }) => ({ ...location, query: { ...query, new: 'query' } })

but I don't want to rule out real use cases.

@eldh
Copy link

eldh commented Aug 2, 2016

We have some cases where params are part of a (known) set, and to calculate filter options we'd need access to the params.

However, I'm not even sure that this api would be the cleanest way to solve that case though. And I suspect we aren't using react-router idiomatically anyway, so feel free to disregard my comments :)

@taion
Copy link
Contributor Author

taion commented Aug 2, 2016

Okay, I think I'll go with (location: Location) => LocationDescriptor API for now and reserve the option to change it before cutting a final release. Thanks for your feedback!

@taion taion closed this as completed Aug 2, 2016
@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
Projects
None yet
Development

No branches or pull requests

5 participants