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

Make isActive work as expected with pathname and query arguments #2218

Closed
ropez opened this issue Oct 9, 2015 · 3 comments
Closed

Make isActive work as expected with pathname and query arguments #2218

ropez opened this issue Oct 9, 2015 · 3 comments

Comments

@ropez
Copy link

ropez commented Oct 9, 2015

Using react-router-bootstrap, and trying to make a generic pagination component, that can generate pagination links without knowing the current path. When clicking this link, I want the URL query to be changed to "?page=2", without changing the rest of the URL:

  <NavItemLink to={this.context.router.getCurrentPathname()} query={{page: 2}}>Page 2</NavItemLink>

This generates the correct links, but the current page link isn't tagged as 'active'. It turns out that router.isActive doesn't work as I expected when the first argument is the pathname, and the query is given as a third argument. More precisely, it doesn't handle arguments in the same way as router.makeHref.

Given a route for the path /categories/:category, and the current URL is /categories/foo, I expected all these to be true:

Router.isActive('categories', {category: 'foo'}, {page: 1})  // true
Router.isActive('/categories/foo?page=1')  // true
Router.isActive('/categories/foo', {}, {page: 1})  // false

However:

Router.isActive(Router.makeHref('/categories/foo', {}, {page: 1}))  // true

Since the name of the current route isn't easily available, this makes it hard to come up with the correct <Link> params.

react-router@0.13.4
react-router-bootstrap@0.18.1
@timdorr
Copy link
Member

timdorr commented Oct 9, 2015

Most of the development effort over here is on react-router 1.0.0. If you bump your react-router-bootstrap to version 0.19.0 or higher, you'll be updated to react-router 1.0.0-rc1. We've proceeded a little farther to rc3, so if @taion has some time to update it to that version as well, this should mostly go away. There are a lot of API changes, but you shouldn't run into this issue.

@taion
Copy link
Contributor

taion commented Oct 9, 2015

Right, the v0.18.x releases of React-Router-Bootstrap are unsupported. v0.19.0 and v0.19.1 both support almost everything in RC3 except for the new hash prop.

I think this will largely be superseded by #2186. For comparison, IIRC, angular-ui-router lets you build links that only override e.g. query parameters without otherwise changing the route you're on.

@taion
Copy link
Contributor

taion commented Oct 9, 2015

I'm going to close this because there's nothing actionable here. Development has moved to the 1.x line rather than the 0.13.x line, so there's no way to address this.

@taion taion closed this as completed Oct 9, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jan 23, 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

3 participants