From 64f26edc7de8a16db95df7c6fa8a710db0d6a70a Mon Sep 17 00:00:00 2001 From: SpainTrain Date: Tue, 15 Sep 2015 00:16:33 -0400 Subject: [PATCH] Docs: Move `isActive` to docs for `History` mixin Closes #1936 --- docs/api/History.md | 38 ++++++++++++++++++++++++++++++++++++-- docs/api/IsActive.md | 36 ------------------------------------ 2 files changed, 36 insertions(+), 38 deletions(-) delete mode 100644 docs/api/IsActive.md diff --git a/docs/api/History.md b/docs/api/History.md index 845dcb7956..780f4cdcdb 100644 --- a/docs/api/History.md +++ b/docs/api/History.md @@ -3,7 +3,7 @@ Adds the router's `history` object to your component instance. **Note**: You do not need this mixin for route components, its already -avaible as `this.props.history`. This is for components deeper in the +available as `this.props.history`. This is for components deeper in the render tree that need access to the router's history object. ### Methods @@ -50,7 +50,18 @@ Stringifies the query into the pathname, using the router's config. Creates a URL, using the router's config. For example, it will add `#/` in front of the `pathname` for hash history. -### Example +#### `isActive(pathname, query)` + +Returns `true` or `false` depending on if the current path is active. +Will be true for every route in the route branch matched by the +`pathname` (child route is active, therefore parent is too). + +##### arguments + +- `pathname` - the full url with or without the query. +- `query` - an object that will be stringified by the router. + +### Examples ```js import { History } from 'react-router' @@ -71,6 +82,29 @@ React.createClass({ }) ``` +Let's say you are using bootstrap and want to get `active` on those `li` +tags for the Tabs: + +```js +import { Link, History } from 'react-router' + +let Tab = React.createClass({ + + mixins: [ History ], + + render() { + let isActive = this.history.isActive(this.props.to, this.props.query) + let className = isActive ? 'active' : '' + return
  • + } + +}) + +// use it just like , and you'll get an anchor wrapped in an `li` +// with an automatic `active` class on both. +Foo +``` + ### But I’m using Classes > Notice how we never told you to use ES6 classes? :) diff --git a/docs/api/IsActive.md b/docs/api/IsActive.md deleted file mode 100644 index 01bb4acf4a..0000000000 --- a/docs/api/IsActive.md +++ /dev/null @@ -1,36 +0,0 @@ -# IsActive Mixin - -Provides `isActive` to a component. - -### Methods - -#### `isActive(pathname, query)` - -Returns `true` or `false` depending on if the current path is active. -Will be true for every route in the route branch matched by the -`pathname` (child route is active, therefore parent is too). - -### Example - -Let's say you are using bootstrap and want to get `active` on those `li` -tags for the Tabs: - -```js -import { Link, IsActive } from 'react-router' - -let Tab = React.createClass({ - - mixins: [ IsActive ], - - render() { - let isActive = this.isActive(this.props.to, this.props.query) - let className = isActive ? 'active' : '' - return
  • - } - -}) - -// use it just like , and you'll get an anchor wrapped in an `li` -// with an automatic `active` class on both. -Foo -```