Can angularjs routes have optional parameter values?

前端 未结 4 1025
清酒与你
清酒与你 2020-11-28 05:37

Can I set a route with optional params (same template and controller, but some params should be ignored if they don\'t exist?

So instead of writing the following two

4条回答
  •  不知归路
    2020-11-28 06:25

    Like @g-eorge mention, you can make it like this:

    module.config(['$routeProvider', function($routeProvider) {
    $routeProvider.
      when('/users/:userId?', {templateUrl: 'template.tpl.html', controller: myCtrl})
    }]);
    

    You can also make as much as u need optional parameters.

提交回复
热议问题