React-router: Params outside component

Created on 2 Aug 2016  路  2Comments  路  Source: ReactTraining/react-router

In reference to this guide and #822

Any way to access params (or queries) while outside of the component?

This may be a feature request as it would be pretty useful.

All 2 comments

i had same issue and solved it like this:

I use redux-saga for side effects, it has select function, so just used that to get app's current state and all the routing info is in the state.

import{select, put, call} from 'redux-saga/effects';
function fitlersSelector(state) {
  return state.routing.locationBeforeTransitions.query;
}

export function* someActionHandler(action) {
  try {
    let filters = yield select(fitlersSelector);

}

State is updated by npm package react-router-redux

import {combineReducers} from 'redux';
import {routerReducer as routing} from 'react-router-redux';

export default combineReducers({
  routing,
  // .... other reducers
});
Was this page helpful?
0 / 5 - 0 ratings