Skip to content

Commit 7c1edc6

Browse files
committed
Update Navigation mixin
1 parent 5276d75 commit 7c1edc6

File tree

6 files changed

+40
-231
lines changed

6 files changed

+40
-231
lines changed

modules/Navigation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var { object } = React.PropTypes;
1313
* mixins: [ Navigation ],
1414
* handleClick(event) {
1515
* event.preventDefault();
16-
* this.transitionTo('aRoute', { the: 'params' }, { the: 'query' });
16+
* this.transitionTo('/the/path', { the: 'query' });
1717
* },
1818
* render() {
1919
* return (
@@ -31,8 +31,8 @@ var Navigation = {
3131
};
3232

3333
var RouterNavigationMethods = [
34-
'makePath',
35-
'makeHref',
34+
'createPath',
35+
'createHref',
3636
'transitionTo',
3737
'replaceWith',
3838
'go',

modules/NavigationMixin.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
import invariant from 'invariant';
2+
import React from 'react';
3+
import { stringifyQuery } from './QueryUtils';
4+
5+
var { func } = React.PropTypes;
26

37
var NavigationMixin = {
48

9+
propTypes: {
10+
stringifyQuery: func
11+
},
12+
13+
getDefaultProps() {
14+
return {
15+
stringifyQuery
16+
};
17+
},
18+
19+
createPath(pathname, query) {
20+
var { stringifyQuery } = this.props;
21+
22+
var queryString;
23+
if (query == null || (queryString = stringifyQuery(query)) === '')
24+
return pathname;
25+
26+
return pathname + (pathname.indexOf('?') === -1 ? '?' : '&') + queryString;
27+
},
28+
529
/**
630
* Returns a string that may safely be used to link to the given
731
* pathname and query.

modules/QueryUtils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import qs from 'qs';
2+
3+
export function stringifyQuery(query) {
4+
return qs.stringify(query, { arrayFormat: 'brackets' });
5+
}
6+
7+
export function parseQueryString(queryString) {
8+
return qs.parse(queryString);
9+
}

modules/Router.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import warning from 'warning';
22
import invariant from 'invariant';
33
import { createClass, createElement, isValidElement, PropTypes } from 'react';
44
import { component, components, history, location, routes } from './PropTypes';
5+
import { parseQueryString } from './QueryUtils';
56
import { createRoutes } from './RouteUtils';
67
import matchRoutes from './matchRoutes';
78
import runTransitionHooks from './runTransitionHooks';
@@ -14,16 +15,6 @@ import ActiveMixin from './ActiveMixin';
1415

1516
var { arrayOf, func, object } = PropTypes;
1617

17-
import qs from 'qs';
18-
19-
function stringifyQuery(query) {
20-
return qs.stringify(query, { arrayFormat: 'brackets' });
21-
}
22-
23-
function parseQueryString(queryString) {
24-
return qs.parse(queryString);
25-
}
26-
2718
var Router = createClass({
2819

2920
mixins: [ NavigationMixin, ScrollManagementMixin, ActiveMixin ],
@@ -69,7 +60,6 @@ var Router = createClass({
6960
propTypes: {
7061
createElement: func,
7162
parseQueryString: func,
72-
stringifyQuery: func,
7363
onError: func,
7464
onUpdate: func,
7565
routes,
@@ -86,8 +76,7 @@ var Router = createClass({
8676
getDefaultProps() {
8777
return {
8878
createElement,
89-
parseQueryString,
90-
stringifyQuery
79+
parseQueryString
9180
};
9281
},
9382

@@ -177,16 +166,6 @@ var Router = createClass({
177166
this._unlisten();
178167
},
179168

180-
createPath(pathname, query) {
181-
var { stringifyQuery } = this.props;
182-
183-
var queryString;
184-
if (query == null || (queryString = stringifyQuery(query)) === '')
185-
return pathname;
186-
187-
return pathname + (pathname.indexOf('?') === -1 ? '?' : '&') + queryString;
188-
},
189-
190169
createElement(component, props) {
191170
return component ? this.props.createElement(component, props) : null;
192171
},

modules/State.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ var { object } = React.PropTypes;
1515
* render() {
1616
* var className = this.props.className;
1717
*
18-
* if (this.isActive('about'))
18+
* if (this.isActive('/about'))
1919
* className += ' is-active';
2020
*
21-
* return React.createElement('a', { className: className }, this.props.children);
21+
* return React.createElement('a', { className }, this.props.children);
2222
* }
2323
* });
2424
*/

modules/URLUtils.js

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

0 commit comments

Comments
 (0)