use-react-router-breadcrumbs
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -66,3 +66,5 @@ 'use strict'; | ||
routes.forEach(function (route, index) { | ||
if (typeof route.path !== 'string' && !route.index) { | ||
var _a; | ||
if (typeof route.path !== 'string' && !route.index && !((_a = route.children) === null || _a === void 0 ? void 0 : _a.length)) { | ||
throw new Error('useBreadcrumbs: `path` or `index` must be provided in every route object'); | ||
@@ -69,0 +71,0 @@ } |
@@ -58,3 +58,5 @@ import React, { createElement } from 'react'; | ||
routes.forEach(function (route, index) { | ||
if (typeof route.path !== 'string' && !route.index) { | ||
var _a; | ||
if (typeof route.path !== 'string' && !route.index && !((_a = route.children) === null || _a === void 0 ? void 0 : _a.length)) { | ||
throw new Error('useBreadcrumbs: `path` or `index` must be provided in every route object'); | ||
@@ -61,0 +63,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-router")):"function"==typeof define&&define.amd?define(["exports","react","react-router"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["react-router-breadcrumbs-hoc"]={},e.React,e.ReactRouter)}(this,(function(e,t,r){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=n(t),o=function(e){return e.join("/").replace(/\/\/+/g,"/")},c=/^:\w+$/,i=function(e){return"*"===e};function u(e,t){var r=e.split("/"),n=r.length;return r.some(i)&&(n+=-2),t&&(n+=2),r.filter((function(e){return!i(e)})).reduce((function(e,t){return c.test(t)?e+3:""===t?e+1:e+10}),n)}function s(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";return e.forEach((function(e,a){if("string"!=typeof e.path&&!e.index)throw new Error("useBreadcrumbs: `path` or `index` must be provided in every route object");if(e.path&&e.index)throw new Error("useBreadcrumbs: `path` and `index` cannot be provided at the same time");var c={relativePath:e.path||"",childrenIndex:a,route:e};if("/"===c.relativePath.charAt(0)){if(!c.relativePath.startsWith(n))throw new Error("useBreadcrumbs: The absolute path of the child route must start with the parent path");c.relativePath=c.relativePath.slice(n.length)}var i=o([n,c.relativePath]),h=r.concat(c);if(e.children&&e.children.length>0){if(e.index)throw new Error("useBreadcrumbs: Index route cannot have child routes");s(e.children,t,h,i)}t.push({path:i,score:u(i,e.index),routesMeta:h})})),t}var h=Symbol("NO_BREADCRUMB"),l=function(e){return e.replace(/^[\s_]+|[\s_]+$/g,"").replace(/[_\s]+/g," ").replace(/^[a-z]/,(function(e){return e.toUpperCase()}))},d=function(e){var r=e.breadcrumb,n=e.match,o=e.location,c=e.props,i=Object.assign({match:n,location:o,key:n.pathname},c||{});return Object.assign(Object.assign({},i),{breadcrumb:"string"==typeof r?t.createElement("span",{key:i.key},r):a.default.createElement(r,Object.assign({},i))})},f=function(e){var t,n=e.currentSection,a=e.disableDefaults,o=e.excludePaths,c=e.location,i=e.pathSection,u=e.branches;return o&&o.some((function(e){return null!=r.matchPath({path:e,end:!0},i)}))?h:(u.some((function(e){var o=e.path,u=e.routesMeta,s=u[u.length-1].route,f=s.breadcrumb;if(!f&&s.index){var p=u[u.length-2];p&&p.route.breadcrumb&&(f=p.route.breadcrumb)}var b=s.caseSensitive,m=s.props,v=r.matchPath({path:o,end:!0,caseSensitive:b},i);return v&&null===f?(t=h,!0):!!v&&(!f&&a?(t=h,!0):(t=d({breadcrumb:f||l(n),match:v,location:c,props:m}),!0))})),t||(a?h:function(e){var t=e.currentSection,n=e.location,a=e.pathSection,o=r.matchPath({end:!0,path:a},a);return d({breadcrumb:l(t),match:o,location:n})}({pathSection:i,currentSection:"/"===i?"Home":n,location:c})))},p=function(e){var t=e.routes,r=e.location,n=e.options,a=void 0===n?{}:n,o=r.pathname,c=function(e){return e.sort((function(e,t){return e.score!==t.score?t.score-e.score:function(e,t){return e.length===t.length&&e.slice(0,-1).every((function(e,r){return e===t[r]}))?e[e.length-1]-t[t.length-1]:0}(e.routesMeta.map((function(e){return e.childrenIndex})),t.routesMeta.map((function(e){return e.childrenIndex})))}))}(s(t)),i=[];return o.split("?")[0].split("/").reduce((function(e,t,n){var o=t?"".concat(e,"/").concat(t):"/";if("/"===o&&0!==n)return"";var u=f(Object.assign({currentSection:t,location:r,pathSection:o,branches:c},a));return u!==h&&i.push(u),"/"===o?"":o}),""),i};e.default=function(e,t){return p({routes:e||[],location:r.useLocation(),options:t})},e.getBreadcrumbs=p,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-router")):"function"==typeof define&&define.amd?define(["exports","react","react-router"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["react-router-breadcrumbs-hoc"]={},e.React,e.ReactRouter)}(this,(function(e,t,r){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=n(t),o=function(e){return e.join("/").replace(/\/\/+/g,"/")},c=/^:\w+$/,i=function(e){return"*"===e};function u(e,t){var r=e.split("/"),n=r.length;return r.some(i)&&(n+=-2),t&&(n+=2),r.filter((function(e){return!i(e)})).reduce((function(e,t){return c.test(t)?e+3:""===t?e+1:e+10}),n)}function s(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";return e.forEach((function(e,a){var c;if("string"!=typeof e.path&&!e.index&&!(null===(c=e.children)||void 0===c?void 0:c.length))throw new Error("useBreadcrumbs: `path` or `index` must be provided in every route object");if(e.path&&e.index)throw new Error("useBreadcrumbs: `path` and `index` cannot be provided at the same time");var i={relativePath:e.path||"",childrenIndex:a,route:e};if("/"===i.relativePath.charAt(0)){if(!i.relativePath.startsWith(n))throw new Error("useBreadcrumbs: The absolute path of the child route must start with the parent path");i.relativePath=i.relativePath.slice(n.length)}var h=o([n,i.relativePath]),l=r.concat(i);if(e.children&&e.children.length>0){if(e.index)throw new Error("useBreadcrumbs: Index route cannot have child routes");s(e.children,t,l,h)}t.push({path:h,score:u(h,e.index),routesMeta:l})})),t}var h=Symbol("NO_BREADCRUMB"),l=function(e){return e.replace(/^[\s_]+|[\s_]+$/g,"").replace(/[_\s]+/g," ").replace(/^[a-z]/,(function(e){return e.toUpperCase()}))},d=function(e){var r=e.breadcrumb,n=e.match,o=e.location,c=e.props,i=Object.assign({match:n,location:o,key:n.pathname},c||{});return Object.assign(Object.assign({},i),{breadcrumb:"string"==typeof r?t.createElement("span",{key:i.key},r):a.default.createElement(r,Object.assign({},i))})},f=function(e){var t,n=e.currentSection,a=e.disableDefaults,o=e.excludePaths,c=e.location,i=e.pathSection,u=e.branches;return o&&o.some((function(e){return null!=r.matchPath({path:e,end:!0},i)}))?h:(u.some((function(e){var o=e.path,u=e.routesMeta,s=u[u.length-1].route,f=s.breadcrumb;if(!f&&s.index){var p=u[u.length-2];p&&p.route.breadcrumb&&(f=p.route.breadcrumb)}var b=s.caseSensitive,m=s.props,v=r.matchPath({path:o,end:!0,caseSensitive:b},i);return v&&null===f?(t=h,!0):!!v&&(!f&&a?(t=h,!0):(t=d({breadcrumb:f||l(n),match:v,location:c,props:m}),!0))})),t||(a?h:function(e){var t=e.currentSection,n=e.location,a=e.pathSection,o=r.matchPath({end:!0,path:a},a);return d({breadcrumb:l(t),match:o,location:n})}({pathSection:i,currentSection:"/"===i?"Home":n,location:c})))},p=function(e){var t=e.routes,r=e.location,n=e.options,a=void 0===n?{}:n,o=r.pathname,c=function(e){return e.sort((function(e,t){return e.score!==t.score?t.score-e.score:function(e,t){return e.length===t.length&&e.slice(0,-1).every((function(e,r){return e===t[r]}))?e[e.length-1]-t[t.length-1]:0}(e.routesMeta.map((function(e){return e.childrenIndex})),t.routesMeta.map((function(e){return e.childrenIndex})))}))}(s(t)),i=[];return o.split("?")[0].split("/").reduce((function(e,t,n){var o=t?"".concat(e,"/").concat(t):"/";if("/"===o&&0!==n)return"";var u=f(Object.assign({currentSection:t,location:r,pathSection:o,branches:c},a));return u!==h&&i.push(u),"/"===o?"":o}),""),i};e.default=function(e,t){return p({routes:e||[],location:r.useLocation(),options:t})},e.getBreadcrumbs=p,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "use-react-router-breadcrumbs", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "A hook for displaying and setting breadcrumbs for react router", | ||
@@ -65,2 +65,3 @@ "main": "dist/cjs/index.js", | ||
"react", | ||
"hook", | ||
"router", | ||
@@ -67,0 +68,0 @@ "breadcrumbs", |
@@ -7,3 +7,2 @@ <h3 align="center"> | ||
<a href="https://github.com/icd2k3/use-react-router-breadcrumbs/actions" target="_blank"><img src="https://github.com/icd2k3/use-react-router-breadcrumbs/workflows/Node.js%20CI/badge.svg" /></a> | ||
<a href="https://david-dm.org/icd2k3/use-react-router-breadcrumbs" title="dependencies status"><img src="https://david-dm.org/icd2k3/use-react-router-breadcrumbs/status.svg"/></a> | ||
<a href='https://coveralls.io/github/icd2k3/use-react-router-breadcrumbs?branch=master'><img src='https://coveralls.io/repos/github/icd2k3/use-react-router-breadcrumbs/badge.svg?branch=master' alt='Coverage Status' /></a> | ||
@@ -13,3 +12,3 @@ </p> | ||
<p align="center"> | ||
A small (~1.25kb gzip), flexible, <a href="https://reactjs.org/docs/hooks-intro.html">hook</a> for rendering breadcrumbs with <a href="https://github.com/ReactTraining/react-router">react-router</a> (5.1 and up). | ||
A small (~1.25kb gzip), flexible, <a href="https://reactjs.org/docs/hooks-intro.html">hook</a> for rendering breadcrumbs with <a href="https://github.com/ReactTraining/react-router">react-router 6</a>. | ||
</p> | ||
@@ -26,7 +25,7 @@ | ||
<p align="center"> | ||
<code> | ||
If you'd rather use a Higher Order Component, check out <a href="https://github.com/icd2k3/react-router-breadcrumbs-hoc">react-router-breadcrumbs-hoc</a> | ||
</code> | ||
Using an <b>older version</B> of <code>react-router</code>? Check out <a href="https://github.com/icd2k3/react-router-breadcrumbs-hoc">react-router-breadcrumbs-hoc</a> which is compatible with v4 and v5. | ||
</p> | ||
--- | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
@@ -52,3 +51,3 @@ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
Render breadcrumbs for `react-router` however you want! | ||
Render breadcrumbs for `react-router` 6 however you want! | ||
@@ -267,6 +266,4 @@ #### Features | ||
`use-react-router-breadcrumbs` uses the same strategy as `React Router v6` to calculate the routing order. | ||
`use-react-router-breadcrumbs` uses the [same strategy](https://reactrouter.com/docs/en/v6/getting-started/concepts#ranking-routes) as `react-router 6` to calculate the routing order. | ||
... in certain cases. Consider the following: | ||
```js | ||
@@ -273,0 +270,0 @@ [ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
33689
510
0
333