i'm simply doing setting this:
app.config(['$routeProvider',function($routeProvider) {
$routeProvider
.when('/asd/:id/:slug',{
templateUrl:'views/home/index.html',
controller:'Home',
publicAccess:true,
sessionAccess:true
});
:id and :slug are dynamic params.
Now i would like to check if current url matches
that route (/asd/:id/:slug
)
for example the url : asd/5/it-is-a-slug
which is the simplest way?
i tryed this :
$rootScope.$on('$routeChangeStart', function(){
console.log($route.current);
});
but sometimes it returns nothing in console while switching page routes
You can try something like this:
Then inside the SecurityFactory you can check the validity of the params. For example with RegExp.
Current route allows you to use regular expression. Inject
$route
service and explore current route object. Namelyregexp
part:This is how you can use it (example from controller method to check if current menu item (which has dynamic parts) should be activated):
Not a very elegant solution, and I have only tested it in Chrome DevTools, but it seems to work:
It seems that the routes property of the $routes service is an object literal with the keys set to the patterns for each route.
For others wanting to use this, just replace
'/asd/:id/:slug'
with the pattern that you used when you defined your route.Also if you want to match the
otherwise
path, just use$route.routes['null']
Disclaimer: This is just a workaround that I found and which works for me. Given that this behavior is not documented, and that I didn't test it to see if it works in all scenarios, use it at your own risk.