Updating URL in Angular JS without re-rendering view

前端 未结 9 1875
情书的邮戳
情书的邮戳 2020-12-04 08:33

I\'m building a dashboard system in AngularJS and I\'m running into an issue with setting the url via $location.path

In our dashboard, we have a bunch o

9条回答
  •  渐次进展
    2020-12-04 08:58

    In fact, a view will be rendered everytime you change a url. Thats how $routeProvider works in Angular but you can pass maximizeWidgetId as a querystring which does not re-render a view.

    App.config(function($routeProvider) {
      $routeProvider.when('/dashboard/:dashboardId', {reloadOnSearch: false});
    });
    

    When you click a widget to maximize:

    Maximum This Widget
    or
    $location.search('maximizeWidgetId', 1);
    

    The URL in addressbar would change to http://app.com/dashboard/1?maximizeWidgetId=1

    You can even watch when search changes in the URL (from one widget to another)

    $scope.$on('$routeUpdate', function(scope, next, current) {
       // Minimize the current widget and maximize the new one
    });
    

提交回复
热议问题