This works with menu entries defined in front matter, and it works with menu entries defined in site configuration if you specify pageRef instead of url in your configuration.
In your example above, if .link represents the url property of the menu entry, strip the fragment before comparing.
I don’t create menu via config. I make it custom. Essentially, I need to check on a normal page whether the current page with the anchor is the one specified in the condition.
Thank you for providing the test repository. I now understand what you are trying to do: add dynamic functionality to a static page. You’ll need some JavaScript for that, updating the class based on window.location.hash.
I don’t think it’s worth the effort or additional complexity.