mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
28 lines
940 B
TypeScript
28 lines
940 B
TypeScript
/// <reference types="redux" />
|
|
/// <reference types="react-router" />
|
|
|
|
import { createStore, combineReducers, applyMiddleware } from 'redux';
|
|
import { browserHistory } from 'react-router';
|
|
import { syncHistoryWithStore, routerReducer, routerMiddleware, push, replace, go, goForward, goBack } from 'react-router-redux';
|
|
|
|
const reducer = combineReducers({ routing: routerReducer });
|
|
|
|
// Apply the middleware to the store
|
|
const middleware = routerMiddleware(browserHistory);
|
|
const store = createStore(
|
|
reducer,
|
|
applyMiddleware(middleware)
|
|
);
|
|
|
|
// Create an enhanced history that syncs navigation events with the store
|
|
const history = syncHistoryWithStore(browserHistory, store);
|
|
history.listen(location => console.log(location) );
|
|
history.unsubscribe();
|
|
|
|
// Dispatch from anywhere like normal.
|
|
store.dispatch(push('/foo'));
|
|
store.dispatch(replace('/foo'));
|
|
store.dispatch(go(1));
|
|
store.dispatch(goForward());
|
|
store.dispatch(goBack());
|