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

Jardilio route redirect fix #14658

Conversation

petebacondarwin
Copy link
Contributor

See #3332

… `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.
@petebacondarwin
Copy link
Contributor Author

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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

@gkalpak
Copy link
Member

gkalpak commented May 24, 2016

Where are the docs ? 😛

@gkalpak
Copy link
Member

gkalpak commented May 24, 2016

I would also mention resolve among the things that don't get processed in the BC notice.

@@ -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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about resolve?

@petebacondarwin
Copy link
Contributor Author

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

@petebacondarwin
Copy link
Contributor Author

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`.
@petebacondarwin
Copy link
Contributor Author

@gkalpak and @Narretz PTAL!

@Narretz
Copy link
Contributor

Narretz commented May 24, 2016

LGTM

@Narretz
Copy link
Contributor

Narretz commented May 24, 2016

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

their --> there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aghast!

@gkalpak
Copy link
Member

gkalpak commented May 24, 2016

The commit message mentions that null cancels the redirection. Remove it when merging to avoid confusion.

LGTM

EDIT: Too slow 😞

@petebacondarwin
Copy link
Contributor Author

Oops. Well I guess I have to fix the null path now then, eh?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants