-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feature (ngRoute) expose #parseRoute as public function #4192
Conversation
Thanks for the PR!
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
@petebacondarwin @btford I've updated this on top of the latest 1.2.2, please review. Thanks! |
@petebacondarwin when you get a sec please review :) |
+1 |
Has this been added to a release? |
@IgorMinar cool if we merge this? |
I've updated it again to latest master. |
The code example in the commit msg is incomplete imho. It only shows how to add And while you touching the commit msg, please change the subject to |
`$route.parseRoute` should be public, allowing you to determine which route a given path will resolve to. This lets you store meta data in your routes config, and take action (e.g. cancel route) before the route changes. Example use case: before navigating, check if the route's feature is feature-switched on or off. If off, cancel the route and display a "feature disabled" popup. Add a `feature` property to each route: ```js $routeProvider.when('/profile', feature: 'profile', template: 'profile.html', controller: 'ProfileCtrl' }); ``` In a main controller, cancel routing and display popup when a route's feature is disabled. ```js $scope.$on('$locationChangeStart', function(e) { // determine the route the user is trying to navigate to var nextRoute = $route.parseRoute($location.path()); // get the feature metadata from the route var nextFeature = nextRoute.$$route.feature; // check if the feature is set to disabled using an app-specific // service var status = AppFeatures.status(nextFeature); if (status === 'disabled'){ // cancel the route e.preventDefault(); // display popup $scope.showFeatureDisabledModal(); } }); ``` Making `parseRoute` public gives your application a lot of flexibility and control over routing.
@vojtajina great feedback, thanks man. Done. |
@vojtajina spoke to me about this issue. he's going to post an update here about our discussion and propose an alternative change that would address this use case. But it comes down to: this change exposes a low level api in order to deal with a deficiency of the higher level api. it might be better to enable route cancelation from within the $routeChangeStart event. |
@geddski I thought about this some more and based on your code example, I think you want to be able to cancel route/url change based on metadata of the next route. Rather than exposing What do you think? Is there any other use case you are trying to cover? |
Btw, this does not fully solve #738. |
@vojtajina adding the ability to cancel
Would you mind providing an example like mine, but with this api? |
An example, assuming the same route definitions as yours: $scope.$on('$routeChangeStart', function(e, currentRoute, nextRoute) {
var nextFeature = nextRoute.$$route.feature;
if (!somehowCheckIfThisFeatureIsAvailable(nextFeature)) {
e.preventDefault();
$scope.showFeatureDisabledModal();
}
}); |
Ok yeah that would be great. |
02dc2aa
to
fd2d6c0
Compare
cad9560
to
f294244
Compare
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
no longer needed |
$route.parseRoute
should be public, allowing you to determine which route a given path will resolve to. This lets you store meta data in your routes config, and take action (e.g. cancel route) before the route changes.Example use case: before navigating, check if the route's feature is feature-switched on or off. If off, cancel the route and display a "feature disabled" popup.
Add a
feature
property to each route:In a main controller, cancel routing and display popup when a route's feature is disabled.
Making
parseRoute
public gives your application a lot of flexibility and control over routing.