Can angularjs routes have default parameter values?

后端 未结 5 1779
余生分开走
余生分开走 2020-12-05 17:21

Can I set a default value of a parameter of a route in AngularJS? Is there a way to have /products/123 and /products/ handled by the same route ?

5条回答
  •  情深已故
    2020-12-05 18:13

    I recognize that this question is old, but still: Why don't you just redirect the "empty" URL to one containing the default productId?

    myModule.config(['$routeProvider', function($routeProvider) {
        $routeProvider.
         when('/products/', {redirectTo: '/products/123'}).
         when('/products/:productId', {templateUrl: 'products.html', controller: ProductsCtrl})
    }]);
    

提交回复
热议问题