UNPKG

mwouter

Version:

A minimalistic routing for React and Preact, Memory Edition. Nothing extra, just HOOKS.

22 lines (19 loc) 506 B
'use strict'; // Generates static `useLocation` hook. The hook always // responds with initial path provided. // You can use this for server-side rendering. var staticLocation = (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; }; module.exports = staticLocation;