Angular js - check if current url matches the route (with dynamic url params)

后端 未结 3 412
一生所求
一生所求 2020-12-15 08:11

i\'m simply doing setting this:

app.config([\'$routeProvider\',function($routeProvider) {
  $routeProvider
  .when(\'/asd/:id/:slug\',{
    templateUrl:\'vie         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 08:44

    You can try something like this:

      $routeProvider.when('/asd/:id/:slug', {
        templateUrl: '/views/template.html',
        controller: 'YourController',
        resolve: {
          data: ['$route', 'SecurityFactory',
            function ($route, SecurityFactory) {
    
              var id= parseInt($route.current.params.id, 10);
              var slug= $route.current.params.slug;
    
              SecurityFactory.checkParams(id, slug);
            }
          ]
        }
      });
    

    Then inside the SecurityFactory you can check the validity of the params. For example with RegExp.

提交回复
热议问题