-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Jardilio route redirect fix #14658
Jardilio route redirect fix #14658
Conversation
… `redirectTo` routes If a route defines a `redirectTo` value, the current route should stop processing the route and instead wait to process the route of the redirect. Currently, what is happening is that Angular detects a redirectTo value and updates $location, but then continues processing the route that was intended to be redirected. Templates are loaded, resolves are processed, ng-view then updates the view with a new template and instantiates the controller all for a route that should have been redirected. A common use case for assigning a function to the redirectTo is to validation authentication, permission check, or some other logic to determine if the route should continue or redirect else where. In the end, this happens, but in between, unexpected results may occur by updating the view and instantiating controllers for logic that wasn't expected to be executed. http://plnkr.co/edit/8QlA0ouuePH3p35Ntmjy?p=preview This commit checks for a url change after a potential redirect, it the url changed, and is not `null` nor `undefined`, exit out and don't process current route change. Closes angular#3332 BREAKING CHANGE The $route service no longer instantiates controllers nor gets templates for routes that have a `redirectTo` that is a defined value and different to the current route url.
I accidentally changed the authorship of the first commit. I will change back before merging... |
@@ -1,6 +1,6 @@ | |||
'use strict'; | |||
|
|||
describe('$route', function() { | |||
fdescribe('$route', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops
Where are the docs ? 😛 |
I would also mention |
@@ -1061,6 +1061,55 @@ describe('$route', function() { | |||
.toEqual(['http://server/#!/bar/id3?extra=eId', true, null]); | |||
}); | |||
}); | |||
|
|||
it('should not instantiate controller or process template for a redirected route', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about resolve
?
So at the moment null works differently so this pr does not change that. We should consider making null work like undefined in a follow up pr |
I'll add checks commit message and docs for resolve |
… `redirectTo` routes If a route defines a `redirectTo` value, the current route should stop processing the route and instead wait to process the route of the redirect. Currently, what is happening is that Angular detects a redirectTo value and updates $location, but then continues processing the route that was intended to be redirected. Templates are loaded, resolves are processed, ng-view then updates the view with a new template and instantiates the controller all for a route that should have been redirected. A common use case for assigning a function to the redirectTo is to validation authentication, permission check, or some other logic to determine if the route should continue or redirect else where. In the end, this happens, but in between, unexpected results may occur by updating the view and instantiating controllers for logic that wasn't expected to be executed. http://plnkr.co/edit/8QlA0ouuePH3p35Ntmjy?p=preview This commit checks for a url change after a potential redirect, it the url changed, and is not `null` nor `undefined`, exit out and don't process current route change. Closes angular#3332 BREAKING CHANGE The $route service no longer instantiates controllers nor calls resolves or template functions for routes that have a `redirectTo` unless the `redirectTo` is a function that returns `undefined`.
LGTM |
Don't forget to change back the authorship though! |
* Routes that specify `redirectTo` will not have their controllers, template functions | ||
* or resolves called, the `$location` will be changed to the redirect url and route | ||
* processing will stop. The exception to this is if the `redirectTo` is a function that | ||
* returns `undefined`. In this case the route transition occurs as though their was no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
their --> there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aghast!
The commit message mentions that LGTM EDIT: Too slow 😞 |
Oops. Well I guess I have to fix the |
See #3332