DEV Community

Chakir Ayoub
Chakir Ayoub

Posted on

Mat menu angular 7

Hello everyone, I hope you are doing well! I have a question. I have a table that contains sub-tables. The values of the main table are loaded from the backend, while for the subtables, I have a list in the TypeScript file, and each element has several sub-elements. The problem is that there are elements for which the user must have a specific role to access them, but they are displayed.

My question is: how to display a message when the user clicks on one of these elements? I want to be able to know if he clicks on it, and if the user has the rights, he will be redirected to a page. How to proceed for this?

Thank you in advance for your advice

Top comments (2)

Collapse
 
chakirayoub profile image
Chakir Ayoub

The solution to this problem is to check the user’s role before redirecting them to a new page in the guard. I created a guard where I check their role. If they are authorized, I redirect them; otherwise, an error message is displayed.

Collapse
 
akbaran profile image
akbaran

Feels good to find the solution doesn't! Onward you go, Chakir! Thanks for sharing the solution.