How could i implement active router link if i have dymanic list of routes and cant assign a fixed route ?

I tried to implement a function which on click send index and search in DOM its array position in sidebar.
It works, but when we delete or add one more section, on update, it lost. Maybe someone have another ideas. Actual code:

A simple way is to use
routerLinkto using therouterLinkActivefunctionality. A way here is to bind the data like this:Code
HTML
This is a easy way. And if you don't wanna use
routerLinkyou need to do it by yourself. One way is to usengClass. You check if theactivatedRouteurl is home as example. Then you set a variable to "home" and check it withngClasslike this:Code
HTML