Option on $location to allow hash/path change w/o reloading the route
We have a paradigm in our app that user's create new things on the same page that they view things. So our route is like /thing/:id. When creating a new thing they go to /thing/new. Once the thing has been successfully saved we want to change the route to /thing/1234 (or whatever its new id is). Now the partial doesnt need to be reloaded because the data is all the same. We just want the path to be updated so a user can now bookmark the correct link, etc.
Having an option on $location (not on the route definition) to enable/disable route loading would work but I'm sure there are other ways to implement the feature.
+1, having the same issue.
@cgross Since the $location service uses JQuery-style method chaining, and all commands are deferred until $digest anyway, I suggest adding a new chaining method, e.g. reload(boolean):
$location.path("/thing/"+thing.id).replace().reload(false)
P.S. Is this the Chris Gross that started the Eclipse Nebula project?
Yup :)
+1 :+1:
+1
Right now, we're using a dirty hack to get around this problem.
$scope.$on('$locationChangeSuccess', function(event) {
// Want to prevent re-loading when going from /dataEntry/1 to some other dataEntry path
if ($route && $route.current && $route.current.$route.templateUrl.indexOf('dataEntry') > 0) {
$route.current = lastRoute; //Does the actual prevention of routing
}
});
+1
+1
+1
+1
+1
Here is my attempt at fixing this by supporting preventDefault() for $routeChangeStart. What do you think about that?
Commit : https://github.com/redhotsly/angular.js/commit/f8ac46e6ac9d76cf855077d21b68b4c2c8043db1
I've been working into @qualidafial approach for a few days and now the PR is ready. I've created a new notify method that allows skipping the location change notification for one time. This should avoid triggering any route change or reload.
This doesn't touch the routing system, so you don't have to change your route definitions. It will still work even if you use ui-router instead of the standard AngularJS routing system.
Example: $location.path('/client/2').replace().notify(false);
I've also worked some tests and documentation bits.
+1
another +1 Using @lrlopez' pull request already. Works like a charm.
+1
+1
Unfortunately PR https://github.com/angular/angular.js/pull/2398 has been rejected by the Angular team as skipping notifications could lead to inconsistencies between the actual URL and the current route. There is a long explanation at the end of the discussion.
I don't need this feature in any of my projects, but I'll keep it in my repository so it can be merged if you wish. Just let me know if it gets out of sync with the master branch so I can rebase the changes. Thanks!
+1
+1, need this :(
+1