@@ -7,7 +7,7 @@ import "directives/router_outlet.dart" show RouterOutlet;
7
7
import "package:angular2/src/facade/lang.dart" show Type, isBlank, isPresent;
8
8
import "package:angular2/src/facade/collection.dart" show ListWrapper;
9
9
import "package:angular2/src/facade/async.dart"
10
- show EventEmitter, Stream, PromiseWrapper;
10
+ show EventEmitter, Stream, PromiseWrapper, ObservableWrapper ;
11
11
import "package:angular2/src/facade/collection.dart" show StringMapWrapper;
12
12
import "package:angular2/src/facade/exceptions.dart" show BaseException;
13
13
import "router_url_serializer.dart" show RouterUrlSerializer;
@@ -45,9 +45,11 @@ class Router {
45
45
Location _location;
46
46
Tree <RouteSegment > _prevTree;
47
47
Tree <UrlSegment > _urlTree;
48
+ dynamic _locationSubscription;
48
49
EventEmitter _changes = new EventEmitter ();
49
50
Router (this ._rootComponent, this ._rootComponentType, this ._componentResolver,
50
51
this ._urlSerializer, this ._routerOutletMap, this ._location) {
52
+ this ._setUpLocationChangeListener ();
51
53
this .navigateByUrl (this ._location.path ());
52
54
}
53
55
Tree <UrlSegment > get urlTree {
@@ -62,6 +64,16 @@ class Router {
62
64
return this ._navigate (this .createUrlTree (changes, segment));
63
65
}
64
66
67
+ void dispose () {
68
+ ObservableWrapper .dispose (this ._locationSubscription);
69
+ }
70
+
71
+ void _setUpLocationChangeListener () {
72
+ this ._locationSubscription = this ._location.subscribe ((change) {
73
+ this ._navigate (this ._urlSerializer.parse (change["url" ]));
74
+ });
75
+ }
76
+
65
77
Future _navigate (Tree <UrlSegment > url) {
66
78
this ._urlTree = url;
67
79
return recognize (this ._componentResolver, this ._rootComponentType, url)
0 commit comments