Search code examples
angularurlauth-guard

how to match url that contains dynamic placeholder


so I'm Trying to add route guard using angular and I have a URL that contains dynamic placeholder

domain/profile/:id/public => ex. domain/profile/1/public

and i want to check if the targeted URL is the same URL as for this page or not

I tried

domain/profile/*/public , domain/profile/:id/public 

the condition is never true ,,

i get the targeted url from the state snapshot and check wether it matches a certain route that i have then do my checks for roles meaning i do not create a guard for each route so i want to match the targeted url with the route i already have ,, targted url could be /4 or /5 or /6 ,, the url i have should something that present all numbers 4,5,6, .... or whatever


Solution

  • so i got an answer from a friend on social media

    let profileRegExp = RegExp('/profile/[1-9][0-9]*/public');
    if(profileRegExp.test(state.url)) {
      // my roles check here  
    }
    

    thanks ....