Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(ngRoute): add method $route.silent(path) for change location path without triggering route controller #5860

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/ngRoute/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,24 @@ function $RouteProvider(){
reload: function() {
forceReload = true;
$rootScope.$evalAsync(updateRoute);
}
},

/**
* @ngdoc method
* @name ngRoute.$route#silent
* @methodOf ngRoute.$route
* @param {string} path New location path
*
* @description
* Call $location.path(path) method without calling route controller
* for silent change current location path
*/
silent: function(path) {
$location.path(path);
$route.$$silentChangePath = $location.path();
},

$$silentChangePath: false
};

$rootScope.$on('$locationChangeSuccess', updateRoute);
Expand Down Expand Up @@ -484,6 +501,12 @@ function $RouteProvider(){
}

function updateRoute() {

// don't call route controller if silent mode enabled for this path
var silentPath = $route.$$silentChangePath;
$route.$$silentChangePath = false;
if (silentPath === $location.path()) return;

var next = parseRoute(),
last = $route.current;

Expand Down