Skip to content

Commit f3a44f1

Browse files
committed
[fixed] React 0.13 compatibility
1 parent 8c6b8a9 commit f3a44f1

File tree

8 files changed

+209
-251
lines changed

8 files changed

+209
-251
lines changed

docs/api/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
React Router API
1+
React Router API
22
================
33

44
- [`Router.run`](/docs/api/run.md)
55
- [`Router.create`](/docs/api/create.md)
6+
- [`Router Context`](/docs/api/RouterContext.md)
67
- [`Location`](/docs/api/Location.md)
78
- [`Transition`](/docs/api/Transition.md)
89

docs/api/RouterContext.md

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
API: Router Context
2+
===================
3+
4+
The `context` feature of React is undocumented because its not
5+
completely baked yet, however, it is commited to by the React team and
6+
we use it with great effect in the Router. There are plans to make
7+
reliance on context optional, but for now, this is what we use.
8+
9+
You access the router inside of route handlers with
10+
`this.context.router`. Its got a few useful methods on it.
11+
12+
### `transitionTo(routeNameOrPath, [params[, query]])`
13+
14+
Programmatically transition to a new route.
15+
16+
#### Examples
17+
18+
```js
19+
this.context.router.transitionTo('user', {id: 10}, {showAge: true});
20+
this.context.router.transitionTo('about');
21+
this.context.router.transitionTo('/users/10?showAge=true');
22+
this.context.router.transitionTo('http://example.com/users/10?showAge=true');
23+
```
24+
25+
### `replaceWith(routeNameOrPath, [params[, query]])`
26+
27+
Programmatically replace current route with a new route. Does not add an
28+
entry into the browser history.
29+
30+
#### Examples
31+
32+
```js
33+
this.context.router.replaceWith('user', {id: 10}, {showAge: true});
34+
this.context.router.replaceWith('about');
35+
this.context.router.replaceWith('/users/10?showAge=true');
36+
```
37+
38+
### `goBack()`
39+
40+
Programmatically go back to the last route and remove the most recent
41+
entry from the browser history. Returns `true` unless it's the first entry
42+
in the app history.
43+
44+
#### Example
45+
46+
```js
47+
this.context.router.goBack();
48+
```
49+
50+
If you want to make sure there was a history entry to go back to, use the return value:
51+
52+
```js
53+
if (!this.context.router.goBack()) {
54+
this.context.router.transitionTo('/otherpage')
55+
}
56+
```
57+
58+
### `makePath(routeName, params, query)`
59+
60+
Creates a URL path to a route.
61+
62+
### `makeHref(routeName, params, query)`
63+
64+
Creates an `href` to a route.
65+
66+
#### Example
67+
68+
```js
69+
// given a route like this:
70+
// <Route name="user" path="users/:userId"/>
71+
this.context.router.makeHref('user', {userId: 123}); // "users/123"
72+
```
73+
74+
### `getPath()`
75+
76+
Returns the current URL path, including query string.
77+
78+
### `getPathname()`
79+
80+
Returns the current URL path without the query string.
81+
82+
### `getParams()`
83+
84+
Returns a hash of the currently active URL params.
85+
86+
### `getQuery()`
87+
88+
Returns a hash of the currently active query params.
89+
90+
### `isActive(routeName, params, query)`
91+
92+
Returns `true` if a route, params, and query are active, `false`
93+
otherwise.
94+
95+
### `getRoutes()`
96+
97+
Returns an array of the currently active routes, in nesting order.
98+
99+
Examples
100+
--------
101+
102+
Often you'll want access to params and query:
103+
104+
```js
105+
// route
106+
<Route name="user" path="user/:name" handler={User} />
107+
108+
// handler
109+
var User = React.createClass({
110+
render: function () {
111+
var name = this.context.router.getParams().name;
112+
return (
113+
<div>
114+
<h1>{name}</h1>
115+
</div>
116+
);
117+
}
118+
});
119+
```
120+
121+
Let's say you are using bootstrap and want to get `active` on those `li`
122+
tags for the Tabs:
123+
124+
```js
125+
var Link = require('react-router').Link;
126+
127+
var Tab = React.createClass({
128+
render: function () {
129+
var { router } = this.context;
130+
var isActive = router.isActive(this.props.to, this.props.params, this.props.query);
131+
var className = isActive ? 'active' : '';
132+
var link = (
133+
<Link {...this.props} />
134+
);
135+
return <li className={className}>{link}</li>;
136+
}
137+
138+
});
139+
140+
// use it just like <Link/>, and you'll get an anchor wrapped in an `li`
141+
// with an automatic `active` class on both.
142+
<Tab to="foo">Foo</Tab>
143+
```
144+
145+
Some navigation:
146+
147+
```js
148+
React.createClass({
149+
render: function() {
150+
var { router } = this.context;
151+
return (
152+
<div onClick={() => router.transitionTo('foo')}>Go to foo</div>
153+
<div onClick={() => router.replaceWith('bar')}>Go to bar without creating a new history entry</div>
154+
<div onClick={() => router.goBack()}>Go back</div>
155+
);
156+
}
157+
});
158+
```
159+
160+

docs/api/components/RouteHandler.md

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ API: `RouteHandler` (component)
44
A `<RouteHandler>` renders the handler of the route at the level of the
55
route hierarchy in which it is used.
66

7+
Router Context
8+
--------------
9+
10+
Router handlers are rendered with a router in their context with useful
11+
methods.
12+
13+
Please see [`Router Context`](/docs/api/RouterContext.md)
14+
715
Static Lifecycle Methods
816
------------------------
917

@@ -53,3 +61,4 @@ var Settings = React.createClass({
5361
//...
5462
});
5563
```
64+

docs/api/mixins/Navigation.md

+1-86
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,5 @@
11
API: `Navigation` (mixin)
22
==========================
33

4-
A mixin for components that need to create URLs and/or initiate
5-
transitions to other routes.
4+
Deprecated, please see [Router Context](/docs/api/RouterContext.md)
65

7-
Instance Methods
8-
----------------
9-
10-
### `transitionTo(routeNameOrPath, [params[, query]])`
11-
12-
Programmatically transition to a new route.
13-
14-
#### Examples
15-
16-
```js
17-
this.transitionTo('user', {id: 10}, {showAge: true});
18-
this.transitionTo('about');
19-
this.transitionTo('/users/10?showAge=true');
20-
this.transitionTo('http://example.com/users/10?showAge=true');
21-
```
22-
23-
### `replaceWith(routeNameOrPath, [params[, query]])`
24-
25-
Programmatically replace current route with a new route. Does not add an
26-
entry into the browser history.
27-
28-
#### Examples
29-
30-
```js
31-
this.replaceWith('user', {id: 10}, {showAge: true});
32-
this.replaceWith('about');
33-
this.replaceWith('/users/10?showAge=true');
34-
```
35-
36-
### `goBack()`
37-
38-
Programmatically go back to the last route and remove the most recent
39-
entry from the browser history. Returns `true` unless it's the first entry
40-
in the app history.
41-
42-
#### Example
43-
44-
```js
45-
this.goBack();
46-
```
47-
48-
If you want to make sure there was a history entry to go back to, use the return value:
49-
50-
```js
51-
if (!this.goBack()) {
52-
this.transitionTo('/otherpage')
53-
}
54-
```
55-
56-
### `makePath(routeName, params, query)`
57-
58-
Creates a URL path to a route.
59-
60-
### `makeHref(routeName, params, query)`
61-
62-
Creates an `href` to a route. Use this along with `State` when you
63-
need to build components similar to `Link`.
64-
65-
#### Example
66-
67-
```js
68-
// given a route like this:
69-
// <Route name="user" path="users/:userId"/>
70-
this.makeHref('user', {userId: 123}); // "users/123"
71-
```
72-
73-
Example
74-
-------
75-
76-
```js
77-
var Navigation = require('react-router').Navigation;
78-
79-
React.createClass({
80-
mixins: [Navigation],
81-
82-
render: function() {
83-
return (
84-
<div onClick={() => this.transitionTo('foo')}>Go to foo</div>
85-
<div onClick={() => this.replaceWith('bar')}>Go to bar without creating a new history entry</div>
86-
<div onClick={() => this.goBack()}>Go back</div>
87-
);
88-
}
89-
});
90-
```

docs/api/mixins/State.md

+1-80
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,6 @@
11
API: `State` (mixin)
22
==========================
33

4-
A mixin for components that need to know about the active params, query
5-
and routes. Any handler on a route with dynamic segments will want to
6-
use this.
4+
Deprecated, please see [Router Context](/docs/api/RouterContext.md)
75

8-
Instance Methods
9-
----------------
106

11-
### `getPath()`
12-
13-
Returns the current URL path, including query string.
14-
15-
### `getPathname()`
16-
17-
Returns the current URL path without the query string.
18-
19-
### `getParams()`
20-
21-
Returns a hash of the currently active URL params.
22-
23-
### `getQuery()`
24-
25-
Returns a hash of the currently active query params.
26-
27-
### `isActive(routeName, params, query)`
28-
29-
Returns `true` if a route, params, and query are active, `false`
30-
otherwise.
31-
32-
### `getRoutes()`
33-
34-
Returns an array of the currently active routes, in nesting order.
35-
36-
Examples
37-
--------
38-
39-
Usually you'll just want access to params and query:
40-
41-
```js
42-
// route
43-
<Route name="user" path="user/:name" handler={User} />
44-
45-
// handler
46-
var User = React.createClass({
47-
mixins: [ Router.State ],
48-
49-
render: function () {
50-
var name = this.getParams().name;
51-
return (
52-
<div>
53-
<h1>{name}</h1>
54-
</div>
55-
);
56-
}
57-
});
58-
```
59-
60-
Let's say you are using bootstrap and want to get `active` on those `li`
61-
tags for the Tabs:
62-
63-
```js
64-
var Link = require('react-router').Link;
65-
var State = require('react-router').State;
66-
67-
var Tab = React.createClass({
68-
69-
mixins: [ State ],
70-
71-
render: function () {
72-
var isActive = this.isActive(this.props.to, this.props.params, this.props.query);
73-
var className = isActive ? 'active' : '';
74-
var link = (
75-
<Link {...this.props} />
76-
);
77-
return <li className={className}>{link}</li>;
78-
}
79-
80-
});
81-
82-
// use it just like <Link/>, and you'll get an anchor wrapped in an `li`
83-
// with an automatic `active` class on both.
84-
<Tab to="foo">Foo</Tab>
85-
```

0 commit comments

Comments
 (0)