Npm
npm install virtual-history-v5
Yarn
yarn add virtual-history-v5
import VirtualHistoryProvider
under BrowserRouter
import { VirtualHistoryProvider } from "virtual-history-v5"
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<BrowserRouter>
<VirtualHistoryProvider>
<Switch>
...
</Switch>
</VirtualHistoryProvider>
</BrowserRouter>,
)
import { useVirtualHistory } from "virtual-history-v5"
const { histories, clearHistory, restartWith, moveTo } = useVirtualHistory()
parameters | description | |
---|---|---|
histories | list of history | |
clearHistory |
index optional target index default: 0 |
clear history list close all history |
restartWith |
location locator of react router like history.push(location)
|
clear all history and replace first order with specific |
moveTo |
key key of location example: kv67oi
|
change the current location to target if target stay before current it uses go(-...)if target stay after current it uses go(...) |