Skip to content

Commit 93d4901

Browse files
committed
Merge pull request #1946 from SpainTrain/1936-isactive-docs
Docs: Move `isActive` to docs for `History` mixin
2 parents fa46586 + 64f26ed commit 93d4901

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

docs/api/History.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Adds the router's `history` object to your component instance.
44

55
**Note**: You do not need this mixin for route components, its already
6-
avaible as `this.props.history`. This is for components deeper in the
6+
available as `this.props.history`. This is for components deeper in the
77
render tree that need access to the router's history object.
88

99
### Methods
@@ -50,7 +50,18 @@ Stringifies the query into the pathname, using the router's config.
5050
Creates a URL, using the router's config. For example, it will add `#/` in
5151
front of the `pathname` for hash history.
5252

53-
### Example
53+
#### `isActive(pathname, query)`
54+
55+
Returns `true` or `false` depending on if the current path is active.
56+
Will be true for every route in the route branch matched by the
57+
`pathname` (child route is active, therefore parent is too).
58+
59+
##### arguments
60+
61+
- `pathname` - the full url with or without the query.
62+
- `query` - an object that will be stringified by the router.
63+
64+
### Examples
5465

5566
```js
5667
import { History } from 'react-router'
@@ -71,6 +82,29 @@ React.createClass({
7182
})
7283
```
7384

85+
Let's say you are using bootstrap and want to get `active` on those `li`
86+
tags for the Tabs:
87+
88+
```js
89+
import { Link, History } from 'react-router'
90+
91+
let Tab = React.createClass({
92+
93+
mixins: [ History ],
94+
95+
render() {
96+
let isActive = this.history.isActive(this.props.to, this.props.query)
97+
let className = isActive ? 'active' : ''
98+
return <li className={className}><Link {...this.props}/></li>
99+
}
100+
101+
})
102+
103+
// use it just like <Link/>, and you'll get an anchor wrapped in an `li`
104+
// with an automatic `active` class on both.
105+
<Tab href="foo">Foo</Tab>
106+
```
107+
74108
### But I’m using Classes
75109

76110
> Notice how we never told you to use ES6 classes? :)

docs/api/IsActive.md

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)