Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bare-routes

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bare-routes - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

2

dist/esm/index.js

@@ -1,1 +0,1 @@

import e,{useState as t,useCallback as r,useEffect as n,useMemo as o,createContext as i,useContext as a,forwardRef as c}from"react";function u(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function f(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null!=r){var n,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return l(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function p(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?s(Object(r),!0).forEach((function(t){u(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var v=function(i){var a=i.children,c=i.render,u=i.skipInitialRender,l=void 0!==u&&u,s=f(t({current:new URL(window.location.href),next:l?void 0:new URL(window.location.href),content:a}),2),v=s[0],y=v.current,b=v.next,h=v.shouldScroll,g=v.content,w=s[1],O=r((function(e,t){var r=new URL(e,y);return r.origin!==(null==y?void 0:y.origin)?(window.location.assign(e),!1):r.pathname===y.pathname&&r.search===y.search?(r.hash!==y.hash&&window.location.assign(e),!1):(null!=t&&t.replace?window.history.replaceState(void 0,"",e):window.history.pushState(void 0,"",e),w((function(e){var n;return p(p({},e),{},{next:r,shouldScroll:null===(n=null==t?void 0:t.scroll)||void 0===n||n})})),!0)}),[y]);n((function(){if(b){var e=new AbortController,t=c({url:b,abortSignal:e.signal});return"function"==typeof t.then?t.then((function(t){e.signal.aborted||w((function(e){return p(p({},e),{},{current:b,next:void 0,content:t})}))})):w((function(e){return p(p({},e),{},{current:b,next:void 0,content:t})})),function(){e.abort()}}}),[c,b]),n((function(){if(h)if(y.hash&&"#"!==y.hash){var e=document.getElementById(y.hash.slice(1));e?e.scrollIntoView():window.scrollTo({left:0,top:0})}else window.scrollTo({left:0,top:0})}),[y,h]),n((function(){window.addEventListener("popstate",(function(){w((function(e){return p(p({},e),{},{next:new URL(window.location.href)})}))}))}),[]);var m=o((function(){return{current:y,next:b,navigate:O}}),[y,O,b]);return e.createElement(d.Provider,{value:m},g)},y=function(t){var r=t.children,n=t.url,i=o((function(){return{current:n,navigate:function(){throw new Error("navigate() cannot be used on server side")}}}),[n]);return e.createElement(d.Provider,{value:i},r)},d=i({current:new URL("https://example.com"),navigate:function(){throw new Error("navigate() called outside of <Router />")}});function b(){return a(d)}function h(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var g=c((function(t,r){var n=t.navigate,o=t.onClick,i=h(t,["navigate","onClick"]);return e.createElement("a",Object.assign({},i,{ref:r,onClick:function(e){null==o||o(e),e.defaultPrevented||void 0===e.currentTarget.href||0!==e.button||e.shiftKey||e.altKey||e.ctrlKey||e.currentTarget.target||(n(e.currentTarget.href),e.preventDefault())}}))}));g.displayName="BaseLink";var w=c((function(t,r){var n=b().navigate;return e.createElement(g,Object.assign({},t,{navigate:n,ref:r}))}));function O(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function m(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?O(Object(r),!0).forEach((function(t){u(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):O(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}w.displayName="Link";var j=c((function(t,r){var n=t.currentRouteClass,o=t.nextRouteClass,i=t.nextRouteStyle,a=t.currentRouteStyle,c=t.onCompareUrls,u=void 0===c?P:c,l=t.className,f=t.style,s=h(t,["currentRouteClass","nextRouteClass","nextRouteStyle","currentRouteStyle","onCompareUrls","className","style"]),p=b(),v=p.navigate,y=p.current,d=p.next,w=l?[l]:[];if(void 0!==s.href&&(n||o)){var O=new URL(s.href,y);d&&u(d,O)&&(o&&w.push(o),i&&(f=m(m({},f),i))),y&&u(y,O)&&(n&&w.push(n),a&&(f=m(m({},f),a)))}return e.createElement(g,Object.assign({},s,{navigate:v,ref:r,className:w.join(" ")||void 0,style:f}))}));function P(e,t){return e.href===t.href}j.displayName="NavLink";export{w as Link,j as NavLink,v as Router,y as ServerRouter,b as useRouter};
import e,{useState as t,useCallback as r,useEffect as n,useMemo as o,createContext as i,useContext as a,forwardRef as c}from"react";function u(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function f(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null!=r){var n,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return l(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function p(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?s(Object(r),!0).forEach((function(t){u(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var v=function(i){var a=i.children,c=i.render,u=i.skipInitialRender,l=void 0!==u&&u,s=f(t({current:new URL(window.location.href),next:l?void 0:new URL(window.location.href),content:a}),2),v=s[0],y=v.current,b=v.next,h=v.shouldScroll,g=v.content,w=s[1],O=r((function(e,t){var r=new URL(e,y);return r.origin!==(null==y?void 0:y.origin)?(window.location.assign(e),!1):r.pathname===y.pathname&&r.search===y.search?(r.hash!==y.hash&&window.location.assign(e),!1):(null!=t&&t.replace?window.history.replaceState(void 0,"",e):window.history.pushState(void 0,"",e),w((function(e){var n;return p(p({},e),{},{next:r,shouldScroll:null===(n=null==t?void 0:t.scroll)||void 0===n||n})})),!0)}),[y]);n((function(){if(b){var e=new AbortController,t=c({url:b,abortSignal:e.signal});return"function"==typeof t.then?t.then((function(t){e.signal.aborted||w((function(e){return p(p({},e),{},{current:b,next:void 0,content:t})}))})):w((function(e){return p(p({},e),{},{current:b,next:void 0,content:t})})),function(){e.abort()}}}),[c,b]),n((function(){if(h)if(y.hash&&"#"!==y.hash){var e=document.getElementById(y.hash.slice(1));e?e.scrollIntoView():window.scrollTo({left:0,top:0})}else window.scrollTo({left:0,top:0})}),[y,h]),n((function(){window.addEventListener("popstate",(function(){w((function(e){return p(p({},e),{},{next:new URL(window.location.href)})}))}))}),[]);var m=o((function(){return{current:y,next:b,navigate:O}}),[y,O,b]);return e.createElement(d.Provider,{value:m},g)},y=function(t){var r=t.children,n=t.url,i=o((function(){return{current:n,navigate:function(){throw new Error("navigate() cannot be used on server side")}}}),[n]);return e.createElement(d.Provider,{value:i},r)},d=i({current:new URL("https://example.com"),navigate:function(){throw new Error("navigate() called outside of <Router />")}});function b(){return a(d)}function h(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var g=c((function(t,r){var n=t.navigate,o=t.onClick,i=h(t,["navigate","onClick"]);return e.createElement("a",Object.assign({},i,{ref:r,onClick:function(e){null==o||o(e),e.defaultPrevented||void 0===e.currentTarget.href||0!==e.button||e.shiftKey||e.altKey||e.ctrlKey||e.currentTarget.target||(n(e.currentTarget.href),e.preventDefault())}}))}));g.displayName="BaseLink";var w=c((function(t,r){var n=b().navigate;return e.createElement(g,Object.assign({},t,{navigate:n,ref:r}))}));function O(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function m(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?O(Object(r),!0).forEach((function(t){u(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):O(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}w.displayName="Link";var j=c((function(t,r){var n=t.currentRouteClass,o=t.nextRouteClass,i=t.nextRouteStyle,a=t.currentRouteStyle,c=t.onCompareUrls,u=void 0===c?P:c,l=t.className,f=t.style,s=h(t,["currentRouteClass","nextRouteClass","nextRouteStyle","currentRouteStyle","onCompareUrls","className","style"]),p=b(),v=p.navigate,y=p.current,d=p.next,w=l?[l]:[];if(void 0!==s.href&&(n||o||a||i)){var O=new URL(s.href,y);d&&u(d,O)&&(o&&w.push(o),i&&(f=m(m({},f),i))),y&&u(y,O)&&(n&&w.push(n),a&&(f=m(m({},f),a)))}return e.createElement(g,Object.assign({},s,{navigate:v,ref:r,className:w.join(" ")||void 0,style:f}))}));function P(e,t){return e.href===t.href}j.displayName="NavLink";export{w as Link,j as NavLink,v as Router,y as ServerRouter,b as useRouter};

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(e);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null!=r){var n,o,a=[],i=!0,u=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(a.push(n.value),!t||a.length!==t);i=!0);}catch(e){u=!0,o=e}finally{try{i||null==r.return||r.return()}finally{if(u)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function u(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?i(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var c=e.createContext({current:new URL("https://example.com"),navigate:function(){throw new Error("navigate() called outside of <Router />")}});function l(){return e.useContext(c)}function f(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var s=e.forwardRef((function(e,t){var n=e.navigate,o=e.onClick,a=f(e,["navigate","onClick"]);return r.default.createElement("a",Object.assign({},a,{ref:t,onClick:function(e){null==o||o(e),e.defaultPrevented||void 0===e.currentTarget.href||0!==e.button||e.shiftKey||e.altKey||e.ctrlKey||e.currentTarget.target||(n(e.currentTarget.href),e.preventDefault())}}))}));s.displayName="BaseLink";var p=e.forwardRef((function(e,t){var n=l().navigate;return r.default.createElement(s,Object.assign({},e,{navigate:n,ref:t}))}));function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function v(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}p.displayName="Link";var y=e.forwardRef((function(e,t){var n=e.currentRouteClass,o=e.nextRouteClass,a=e.nextRouteStyle,i=e.currentRouteStyle,u=e.onCompareUrls,c=void 0===u?b:u,p=e.className,d=e.style,y=f(e,["currentRouteClass","nextRouteClass","nextRouteStyle","currentRouteStyle","onCompareUrls","className","style"]),h=l(),w=h.navigate,g=h.current,O=h.next,m=p?[p]:[];if(void 0!==y.href&&(n||o)){var j=new URL(y.href,g);O&&c(O,j)&&(o&&m.push(o),a&&(d=v(v({},d),a))),g&&c(g,j)&&(n&&m.push(n),i&&(d=v(v({},d),i)))}return r.default.createElement(s,Object.assign({},y,{navigate:w,ref:t,className:m.join(" ")||void 0,style:d}))}));function b(e,t){return e.href===t.href}y.displayName="NavLink",exports.Link=p,exports.NavLink=y,exports.Router=function(t){var n=t.children,o=t.render,i=t.skipInitialRender,l=void 0!==i&&i,f=a(e.useState({current:new URL(window.location.href),next:l?void 0:new URL(window.location.href),content:n}),2),s=f[0],p=s.current,d=s.next,v=s.shouldScroll,y=s.content,b=f[1],h=e.useCallback((function(e,t){var r=new URL(e,p);return r.origin!==(null==p?void 0:p.origin)?(window.location.assign(e),!1):r.pathname===p.pathname&&r.search===p.search?(r.hash!==p.hash&&window.location.assign(e),!1):(null!=t&&t.replace?window.history.replaceState(void 0,"",e):window.history.pushState(void 0,"",e),b((function(e){var n;return u(u({},e),{},{next:r,shouldScroll:null===(n=null==t?void 0:t.scroll)||void 0===n||n})})),!0)}),[p]);e.useEffect((function(){if(d){var e=new AbortController,t=o({url:d,abortSignal:e.signal});return"function"==typeof t.then?t.then((function(t){e.signal.aborted||b((function(e){return u(u({},e),{},{current:d,next:void 0,content:t})}))})):b((function(e){return u(u({},e),{},{current:d,next:void 0,content:t})})),function(){e.abort()}}}),[o,d]),e.useEffect((function(){if(v)if(p.hash&&"#"!==p.hash){var e=document.getElementById(p.hash.slice(1));e?e.scrollIntoView():window.scrollTo({left:0,top:0})}else window.scrollTo({left:0,top:0})}),[p,v]),e.useEffect((function(){window.addEventListener("popstate",(function(){b((function(e){return u(u({},e),{},{next:new URL(window.location.href)})}))}))}),[]);var w=e.useMemo((function(){return{current:p,next:d,navigate:h}}),[p,h,d]);return r.default.createElement(c.Provider,{value:w},y)},exports.ServerRouter=function(t){var n=t.children,o=t.url,a=e.useMemo((function(){return{current:o,navigate:function(){throw new Error("navigate() cannot be used on server side")}}}),[o]);return r.default.createElement(c.Provider,{value:a},n)},exports.useRouter=l;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(e);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null!=r){var n,o,a=[],i=!0,u=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(a.push(n.value),!t||a.length!==t);i=!0);}catch(e){u=!0,o=e}finally{try{i||null==r.return||r.return()}finally{if(u)throw o}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function u(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?i(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var c=e.createContext({current:new URL("https://example.com"),navigate:function(){throw new Error("navigate() called outside of <Router />")}});function l(){return e.useContext(c)}function f(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var s=e.forwardRef((function(e,t){var n=e.navigate,o=e.onClick,a=f(e,["navigate","onClick"]);return r.default.createElement("a",Object.assign({},a,{ref:t,onClick:function(e){null==o||o(e),e.defaultPrevented||void 0===e.currentTarget.href||0!==e.button||e.shiftKey||e.altKey||e.ctrlKey||e.currentTarget.target||(n(e.currentTarget.href),e.preventDefault())}}))}));s.displayName="BaseLink";var p=e.forwardRef((function(e,t){var n=l().navigate;return r.default.createElement(s,Object.assign({},e,{navigate:n,ref:t}))}));function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function v(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}p.displayName="Link";var y=e.forwardRef((function(e,t){var n=e.currentRouteClass,o=e.nextRouteClass,a=e.nextRouteStyle,i=e.currentRouteStyle,u=e.onCompareUrls,c=void 0===u?b:u,p=e.className,d=e.style,y=f(e,["currentRouteClass","nextRouteClass","nextRouteStyle","currentRouteStyle","onCompareUrls","className","style"]),h=l(),w=h.navigate,g=h.current,O=h.next,m=p?[p]:[];if(void 0!==y.href&&(n||o||i||a)){var j=new URL(y.href,g);O&&c(O,j)&&(o&&m.push(o),a&&(d=v(v({},d),a))),g&&c(g,j)&&(n&&m.push(n),i&&(d=v(v({},d),i)))}return r.default.createElement(s,Object.assign({},y,{navigate:w,ref:t,className:m.join(" ")||void 0,style:d}))}));function b(e,t){return e.href===t.href}y.displayName="NavLink",exports.Link=p,exports.NavLink=y,exports.Router=function(t){var n=t.children,o=t.render,i=t.skipInitialRender,l=void 0!==i&&i,f=a(e.useState({current:new URL(window.location.href),next:l?void 0:new URL(window.location.href),content:n}),2),s=f[0],p=s.current,d=s.next,v=s.shouldScroll,y=s.content,b=f[1],h=e.useCallback((function(e,t){var r=new URL(e,p);return r.origin!==(null==p?void 0:p.origin)?(window.location.assign(e),!1):r.pathname===p.pathname&&r.search===p.search?(r.hash!==p.hash&&window.location.assign(e),!1):(null!=t&&t.replace?window.history.replaceState(void 0,"",e):window.history.pushState(void 0,"",e),b((function(e){var n;return u(u({},e),{},{next:r,shouldScroll:null===(n=null==t?void 0:t.scroll)||void 0===n||n})})),!0)}),[p]);e.useEffect((function(){if(d){var e=new AbortController,t=o({url:d,abortSignal:e.signal});return"function"==typeof t.then?t.then((function(t){e.signal.aborted||b((function(e){return u(u({},e),{},{current:d,next:void 0,content:t})}))})):b((function(e){return u(u({},e),{},{current:d,next:void 0,content:t})})),function(){e.abort()}}}),[o,d]),e.useEffect((function(){if(v)if(p.hash&&"#"!==p.hash){var e=document.getElementById(p.hash.slice(1));e?e.scrollIntoView():window.scrollTo({left:0,top:0})}else window.scrollTo({left:0,top:0})}),[p,v]),e.useEffect((function(){window.addEventListener("popstate",(function(){b((function(e){return u(u({},e),{},{next:new URL(window.location.href)})}))}))}),[]);var w=e.useMemo((function(){return{current:p,next:d,navigate:h}}),[p,h,d]);return r.default.createElement(c.Provider,{value:w},y)},exports.ServerRouter=function(t){var n=t.children,o=t.url,a=e.useMemo((function(){return{current:o,navigate:function(){throw new Error("navigate() cannot be used on server side")}}}),[o]);return r.default.createElement(c.Provider,{value:a},n)},exports.useRouter=l;
{
"name": "bare-routes",
"version": "0.2.1",
"version": "0.2.2",
"description": "A bare-bones React client-side page router that delegates the actual routing and page loading to user code and only handles history manipulation",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc