UNPKG

react-nested-routes

Version:

React nested routes is a react component which helps you to create nested routes in react application. It also provides a hook to get active path and active index of the route.

2 lines (1 loc) 1.09 kB
"use strict";var f=Object.create;var n=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var L=(t,e)=>{for(var o in e)n(t,o,{get:e[o],enumerable:!0})},d=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of y(e))!x.call(t,a)&&a!==o&&n(t,a,{get:()=>e[a],enumerable:!(s=u(e,a))||s.enumerable});return t};var g=(t,e,o)=>(o=t!=null?f(R(t)):{},d(e||!t||!t.__esModule?n(o,"default",{value:t,enumerable:!0}):o,t)),w=t=>d(n({},"__esModule",{value:!0}),t);var P={};L(P,{default:()=>N,useActivePath:()=>I});module.exports=w(P);var l=g(require("react")),i=require("react-router"),m=require("react/jsx-runtime"),C=t=>{let{children:e,path:o,parent:s}=t;o=o.toLowerCase();let p=(0,i.useLocation)().pathname.toLowerCase().split("/"),c=p.lastIndexOf(s),h;return c!==-1&&(h=o===p[c+1]),h?e:(0,m.jsx)(l.default.Fragment,{})},I=({parent:t})=>{let o=(0,i.useLocation)().pathname.toLowerCase();t=t.toLowerCase();let s=o.split("/"),a=s.lastIndexOf(t),r;return a!==-1&&(r=s[a+1]),r},N=C;