Skip to content

Commit 9cc249e

Browse files
committed
Merge pull request #129 from jmathews/master
Fix handling of query string in client bootstrap and universalRouter
2 parents 9561461 + 48401a8 commit 9cc249e

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"lru-memoize": "0.0.2",
6969
"piping": "0.2.0",
7070
"pretty-error": "^1.1.2",
71+
"query-string": "^2.4.0",
7172
"react": "0.13.3",
7273
"react-document-meta": "^0.1.4",
7374
"react-inline-css": "1.2.1",

src/client.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'babel/polyfill';
33
import React from 'react';
44
import BrowserHistory from 'react-router/lib/BrowserHistory';
55
import Location from 'react-router/lib/Location';
6+
import queryString from 'query-string';
67
import createStore from './redux/create';
78
import ApiClient from './ApiClient';
89
import universalRouter from './universalRouter';
@@ -11,7 +12,9 @@ const client = new ApiClient();
1112

1213
const dest = document.getElementById('content');
1314
const store = createStore(client, window.__data);
14-
const location = new Location(document.location.pathname, document.location.search);
15+
const search = document.location.search;
16+
const query = search && queryString.parse(search);
17+
const location = new Location(document.location.pathname, query);
1518
universalRouter(location, history, store)
1619
.then(({component}) => {
1720
if (__DEVTOOLS__) {

src/universalRouter.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ const getFetchData = (component = {}) => {
1111

1212
export function createTransitionHook(store) {
1313
return (nextState, transition, callback) => {
14+
const { params, location: { query } } = nextState;
1415
const promises = nextState.branch
1516
.map(route => route.component) // pull out individual route components
1617
.filter((component) => getFetchData(component)) // only look at ones with a static fetchData()
1718
.map(getFetchData) // pull out fetch data methods
18-
.map(fetchData => fetchData(store, nextState.params)); // call fetch data methods and save promises
19+
.map(fetchData => fetchData(store, params, query || {})); // call fetch data methods and save promises
1920
Promise.all(promises)
2021
.then(() => {
2122
callback(); // can't just pass callback to then() because callback assumes first param is error

0 commit comments

Comments
 (0)