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) 465 B
import h from"react";import{useLocation as c}from"react-router";import{jsx as l}from"react/jsx-runtime";var d=t=>{let{children:n,path:e,parent:o}=t;e=e.toLowerCase();let r=c().pathname.toLowerCase().split("/"),i=r.lastIndexOf(o),p;return i!==-1&&(p=e===r[i+1]),p?n:l(h.Fragment,{})},u=({parent:t})=>{let e=c().pathname.toLowerCase();t=t.toLowerCase();let o=e.split("/"),a=o.lastIndexOf(t),s;return a!==-1&&(s=o[a+1]),s},y=d;export{y as default,u as useActivePath};