history-query-enhancer
Enhance session history with query property.
Install
npm i history-query-enhancer
Usage
A query enhancer for history
v4, since it no longer supports query
property.
Examples
Basic
;;; const history = ;
console; // `location` has `query` property // /the/path?the=queryhistory; // /the/path?the=queryhistory; // /the/path?another=queryhistory; history; history; // /the/path?the=queryhistory;
It also supports HashHistory
and MemoryHistory
.
react-router
Using with ; const App = <Router history=history> <Route path="/the/path" exact component=Home /> /* other routes */ </Router>;
{ const location = thisprops; console; // `location` has `query` property return <Header /> }
; { const location = thisprops; console; // `location` has `query` property return /* */; } Header;
react-router-redux
Using with ; const App = <ConnectedRouter history=history> /* routes */ </ConnectedRouter>
// /the/path?the=query; // /the/path?the=query; // /the/path?another=query;
; const store = const location = storerouter; console; // `location` has `query` property
react-router-redux
and TypeScript
Using with ;;; declare
API
withQuery
It receives a query transformer (such as query-string
, querystring
or qs
) and returns a history enhancer.
You can provide your own query transformer. For example:
; const history = ;
It will simply turn all integer-like query to integer.