Djinn-state history
Djinn-state helpers for history integration
This library is just a wrapper of the history package.
The HistoryService have implemented all the exported functions and its parameters of the history package
(push, go, goBack, goForward, replace, block, createHref)
and with two more functions (pushLocation, replaceLocation) to receive the location object instead of its original ones.
Install
npm npm i --save djinn-state djinn-state-history
yarn yarn add djinn-state djinn-state-history
Using
import { Djinn } from 'djinn-state';
export const djinn = new Djinn();
import { HistoryService } from 'djinn-state-history';
import { djinn } from './djinn';
djinn.register(HistoryService);
djinn.start();
import { HistoryService } from 'djinn-state-history';
import { createBrowserHistory } from 'history';
import { djinn } from './djinn';
import './djinnServices';
const history = createBrowserHistory();
const service = djinn.getService(HistoryService);
service.setHistory(history);
service.push('/home');
Route blocking
Useful for authentication.
import { Djinn } from 'djinn-state';
export const djinn = new Djinn();
import { HistoryBlockerService } from 'djinn-state-history';
export class AuthBlocker extends HistoryBlockerService {
canAccessRoute(location, action){
return true;
}
}
import { djinn } from './djinn';
import { AuthBlocker } from './AuthBlocker';
djinn.register(AuthBlocker);
djinn.start();
import { createBrowserHistory } from 'history';
import { djinn } from './djinn';
import { AuthBlocker } from './AuthBlocker';
import './djinnServices';
const history = createBrowserHistory();
const service = djinn.getService(AuthBlocker);
service.setHistory(history);
service.push('/home');