0.1.0 • Published 4 years ago
@yelo/historian v0.1.0
@yelo/historian
🗿The missing part of history library
Installation
$ yarn add @yelo/historian
Usage
/** /history.ts */
import { createBrowserHistory } from 'history'
import { createHistorian } from '@yelo/historian'
export const history = createBrowserHistory({
basename: '/v4',
forceRefresh: false,
})
// initial historian with history
export const historian = createHistorian(history)
/** /app.ts */
import React from 'react'
import { Route, Switch, Router } from 'react-router-dom'
import { history } from './history'
export const App = () => (
<Router history={history}>
<Switch>
<Route path="/">...</Route>
<Route path="/login">...</Route>
</Switch>
</Router>
)
/** /views/login.ts */
import React, { useCallback } from 'react'
import { historian } from '../history'
const ROOT_URL = '/'
export const View = () => {
const back = useCallback(history.back({ fallback: ROOT_URL }))
return (
<div>
<button onClick={back}>back</button>
</div>
)
}
License
Apache-2.0 © yelo, 2020 - present
0.1.0
4 years ago