forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavigation.js
More file actions
50 lines (43 loc) · 937 Bytes
/
Navigation.js
File metadata and controls
50 lines (43 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React from 'react';
var { object } = React.PropTypes;
/**
* A mixin for components that modify the URL.
*
* Example:
*
* import { Navigation } from 'react-router';
*
* var MyLink = React.createClass({
* mixins: [ Navigation ],
* handleClick(event) {
* event.preventDefault();
* this.transitionTo('/the/path', { the: 'query' });
* },
* render() {
* return (
* <a onClick={this.handleClick}>Click me!</a>
* );
* }
* });
*/
var Navigation = {
contextTypes: {
router: object.isRequired
}
};
var RouterNavigationMethods = [
'createPath',
'createHref',
'transitionTo',
'replaceWith',
'go',
'goBack',
'goForward'
];
RouterNavigationMethods.forEach(function (method) {
Navigation[method] = function () {
var router = this.context.router;
return router[method].apply(router, arguments);
};
});
export default Navigation;