MemoryHistory
Memory history stores the current location in memory. It is designed for use in stateful non-browser environments like tests and React Native.
The full documentation for MemoryHistory can be found here
Usage
import { createMemoryHistory } from "mobx-location-history";
import { reaction } from "mobx";
export const history = createMemoryHistory();
reaction(
() => history.location.pathname,
pathname => {
console.log(pathname);
}
)
history.push()MobX modifications
location: Location deep observable
Original location property wrapped in observable
See documentation here
action: Action reference observable
Original action property wrapped in observable
See documentation here
isBlocked: boolean computed structural
This property is needed to detect block statement provided by original history package
blockersCount: number reference observable
This property is needed to detect block statement provided by original history package
destroy()
This method is needed for destroy all subscriptions and reactions created inside function createMemoryHistory
locationUrl computed structural
This property represents stringified version of the location property
Example:
/*
{ // location
pathname: '/en-US/docs/Location.search',
hash: '',
search: '?q=123'
}
*/
history.locationUrl; // '/en-US/docs/Location.search?q=123'lastBlockedTx: Transition | null reference observable
Last blocked transition.
This property is helpful if you want to watch about blocked history transitions while history is blocked.
More information about blocking history you can find here
will be null if history is not blocked
Example:
import { createBrowserHistory } from "mobx-location-history";
const history = createBrowserHistory();
...
const unblock = history.block(() => {
//
})
...
history.push('/foo/bar');
history.lastBlockedTx; // { // Transition
unblock();
history.lastBlockedTx; // null