Creating a history object is useful if your application uses routing (which most do). As such, arco
makes the creation of various types of history as painless as possible:
Standard
For most applications, use of a standard history is sufficient for routing.
import {
createHistory
} from 'arco';
export default createHistory('hash');
There are three types of standard histories:
- browser (default) = HTML5 History API, using clean URLs and
pushState
(Modern browsers) - hash = Include hash in URL (IE9-)
- memory = In-memory history that does not interact with the browser URL
- Can also pass a second parameter of
options
tocreateHistory
- Can also pass a second parameter of
Custom
In the case you want to use a custom history, you can instead pass a function to createHistory
and return your own:
import createHashHistory from 'history/lib/createHashHistory';
import {
createHistory
} from 'arco';
export default createHistory((useRouterHistory) => {
return useRouterHistory(createHashHistory)({
queryKey: false
});
});
Use with ImmutableJS
If you create your Reducer with isImmutable
set to true
and you want to sync your history with that store, you should use the provided syncHistoryWithImmutableStore
function instead of the standard syncHistoryWithStore
.
import {
syncHistoryWithImmutableStore
} from 'arco';
import history from './history';
import store from './store';
const syncedHistory = syncHistoryWithImmutableStore(history, store);
This is a convenience function that performs the standard syncing method that redux-immutable
requires.