mwouter
Version:
A minimalistic routing for React and Preact, Memory Edition. Nothing extra, just HOOKS.
18 lines (17 loc) • 451 B
JavaScript
// Generates static `useLocation` hook. The hook always
// responds with initial path provided.
// You can use this for server-side rendering.
export default (path = "/", { record = false } = {}) => {
let hook;
const navigate = (to, { replace } = {}) => {
if (record) {
if (replace) {
hook.history.pop();
}
hook.history.push(to);
}
};
hook = () => [path, navigate];
hook.history = [path];
return hook;
};