'React router V6 check or test if a pathname does exist in routes
i wanna check if a route exist in my routes, how can i do that i tried using matchPath but it just matches a pattern to some path, i wanna test if a route exist, is there a way to do it ?
const handleNotifClick = (link, id) => {
setIsFetchingNotifs(true);
// check if "link"(pathname) exist in routes. what should i remplace "exist" with ??
if(exist) navigate(link);
else navigate('/access-denied');
if (acl?.notification?.put_notification_as_seen) axiosPut(`notification/mark-as-seen/${id}`);
};
link is just a string that comes from the api, something like '/products' i wanna check if that link exist in my routes, so i can navigate to it, else i wanna navigate to access-denied
exist is just a placeholder, its the thing that im looking for
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
