Usually, this is handled in the server-side code by adding required classes to the active menu link and its parents as you can see in this examples.
If you use JS to set the active menu link, it can be noticeable that the menu active item is set after page load and the delay can be 2-3seconds. If you use the server-side approach it will be an instance with the page load.
Can I have a JS anyway?
Can you please replace
core/html/src/js/components/menu.js with https://keenthemes.ams3.digitaloceanspaces.com/downloads/menu.js and recompile your assets with gulp or webpack then you can use the KTMenu's new API method as:
var activeLink = menu.getLinkByAttribute("/users/group/add");
Or globally call the below API method to automatically set an active menu link based on the current page URL:
thanks a lot