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

fix($route): update current route upon service instantiation #5681

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/ngRoute/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ function $RouteProvider(){
}
};

updateRoute();
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't thought about this enough, but I wonder if it's safe to just do this (is the $location object in a consistent state this early in the app life cycle.

I think it should be fine...

$rootScope.$on('$locationChangeSuccess', updateRoute);

return $route;
Expand Down
8 changes: 4 additions & 4 deletions test/ngRoute/routeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ describe('$route', function() {
var onChangeSpy = jasmine.createSpy('onChange');

$rootScope.$on('$routeChangeStart', onChangeSpy);
expect($route.current).toBeUndefined();
expect($route.current).toBeDefined();
expect(onChangeSpy).not.toHaveBeenCalled();

$location.path('/unknownRoute');
Expand Down Expand Up @@ -426,15 +426,15 @@ describe('$route', function() {

// init
$rootScope.$on('$routeChangeStart', onChangeSpy);
expect($route.current).toBeUndefined();
expect($route.current).toBeDefined();
expect(onChangeSpy).not.toHaveBeenCalled();


// match otherwise route
$location.path('/unknownRoute');
$rootScope.$digest();

expect(currentRoute).toBeUndefined();
expect(currentRoute).toBeDefined();
expect(nextRoute.templateUrl).toBe('404.html');
expect($route.current.templateUrl).toBe('404.html');
expect(onChangeSpy).toHaveBeenCalled();
Expand Down Expand Up @@ -770,7 +770,7 @@ describe('$route', function() {
var onChangeSpy = jasmine.createSpy('onChange');

$rootScope.$on('$routeChangeStart', onChangeSpy);
expect($route.current).toBeUndefined();
expect($route.current).toBeDefined();
expect(onChangeSpy).not.toHaveBeenCalled();

$location.path('/');
Expand Down