2

我有几个使用相同模板的视图,只有路由参数的数量不同,我该如何设置它以便每次路由更改时都不会重新渲染视图,尝试使用reloadOnSearch: false,但它不起作用一些原因。

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'
        });
}]);
4

1 回答 1

-1

根据文档,您不能path's为一条路线定义多个。因此,在您的情况下,您应该定义两个独特的routes,例如:

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'
    });
}]);

区别,始终使用完整参数调用此 URL,例如:

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

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

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

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

打电话FeedsController的人仍然是独一无二的,只有两个参数:

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

于 2015-06-11T13:15:04.693 回答