preact-router
Version:
Connect your components up to that address bar.
2 lines (1 loc) • 625 B
JavaScript
var e=require("preact"),a=require("preact-router"),r=["className","activeClass","activeClassName","path"];function t(e){var r=a.useRouter()[0];return e.children({url:r.url,path:r.path,matches:!1!==a.exec(r.path||r.url,e.path,{})})}t.Link=function(t){var s=t.className,u=t.activeClass,c=t.activeClassName,l=t.path,n=function(e,a){if(null==e)return{};var r,t,s={},u=Object.keys(e);for(t=0;t<u.length;t++)a.indexOf(r=u[t])>=0||(s[r]=e[r]);return s}(t,r),i=a.useRouter()[0],h=l&&i.path&&a.exec(i.path,l,{})||a.exec(i.url,n.href,{}),p=n.class||s||"",o=h&&(u||c)||"";return n.class=p+(p&&o&&" ")+o,e.h(a.Link,n)},module.exports=t;