1.0.0 • Published 5 years ago
best-matcher v1.0.0
best-matcher
find the best matched string amoung a list that starts with the same prefix;
useage
import { getBestMatch } from "best-matcher";
const currentActiveMenu = getBestMatch(location.href, menus, '/')if the routes follow the hierarchy naming rules, this function will match the most intuitive and logically correct path in the sidemenu.
eg.
if current path is /user/list/detail?uid=123, best match will be /user/list amoung the list of ['/user/manage', '/user/list']