2

I have several views that use the same template, only the number of route params is different, how can I set it up so that the view doesn't get rerendered every time the route changes, tried with reloadOnSearch: false, but it didn't work for some reason.

app.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
        .when('/feeds', {
            templateUrl: 'partials/feeds.html',
            controller: 'FeedsController'
        })
        .when('/feeds/:country', {
            templateUrl: 'partials/feeds.html',
            controller: 'FeedsController'
        })
        .when('/feeds/:country/:competition', {
            templateUrl: 'partials/feeds.html',
            controller: 'FeedsController'
        })
        .otherwise({
            redirectTo: '/feeds'
        });
}]);
alpar
  • 1,577
  • 1
  • 10
  • 7

1 Answers1

-1

According to the documentation, You cannot define multiple path's for one route. So in your case you should define two unique routes like:

app.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
    .when('/feeds/:country/:competition/:event', {
        templateUrl: 'partials/event.html',
        controller: 'EventController'
    })
    .when('/feeds/:country/:competition', {
        templateUrl: 'partials/feeds.html',
        controller: 'FeedsController'
    })
    .otherwise({
        redirectTo: '/feeds'
    });
}]);

Difference, always call this URL with full params like:

http://yourapplication/feeds/false/false/false

http://yourapplication/feeds/1/false/false

http://yourapplication/feeds/1/2/false

http://yourapplication/feeds/1/2/3

And the one who is calling FeedsController is still unique with only two params:

http://yourapplication/feeds/1/2/

lin
  • 17,956
  • 4
  • 59
  • 83
  • I can't use urls like: http://myapplication/feeds/false/false/false, the user has to be able to enter any of the following urls: http://myapplication/feeds/1, http://myapplication/feeds/1/2 or http://myapplication/feeds/1/2/3 without entering "false" – alpar Jun 18 '15 at 14:46