@@ -38,8 +38,10 @@ let _resolveToFalse = PromiseWrapper.resolve(false);
3838export class Router {
3939 navigating : boolean = false ;
4040 lastNavigationAttempt : string ;
41-
42- private _currentInstruction : Instruction = null ;
41+ /**
42+ * The current `Instruction` for the router
43+ */
44+ public currentInstruction : Instruction = null ;
4345
4446 private _currentNavigation : Promise < any > = _resolveToTrue ;
4547 private _outlet : RouterOutlet = null ;
@@ -50,8 +52,8 @@ export class Router {
5052 private _subject : EventEmitter < any > = new EventEmitter ( ) ;
5153
5254
53- constructor ( public registry : RouteRegistry , public parent : Router , public hostComponent : any ) { }
54-
55+ constructor ( public registry : RouteRegistry , public parent : Router , public hostComponent : any ,
56+ public root ?: Router ) { }
5557
5658 /**
5759 * Constructs a child router. You probably don't need to use this unless you're writing a reusable
@@ -83,8 +85,8 @@ export class Router {
8385 }
8486
8587 this . _outlet = outlet ;
86- if ( isPresent ( this . _currentInstruction ) ) {
87- return this . commit ( this . _currentInstruction , false ) ;
88+ if ( isPresent ( this . currentInstruction ) ) {
89+ return this . commit ( this . currentInstruction , false ) ;
8890 }
8991 return _resolveToTrue ;
9092 }
@@ -119,8 +121,8 @@ export class Router {
119121 router . _outlet = outlet ;
120122
121123 var auxInstruction ;
122- if ( isPresent ( this . _currentInstruction ) &&
123- isPresent ( auxInstruction = this . _currentInstruction . auxInstruction [ outletName ] ) ) {
124+ if ( isPresent ( this . currentInstruction ) &&
125+ isPresent ( auxInstruction = this . currentInstruction . auxInstruction [ outletName ] ) ) {
124126 return router . commit ( auxInstruction ) ;
125127 }
126128 return _resolveToTrue ;
@@ -137,8 +139,8 @@ export class Router {
137139 router = router . parent ;
138140 instruction = instruction . child ;
139141 }
140- return isPresent ( this . _currentInstruction ) &&
141- this . _currentInstruction . component == instruction . component ;
142+ return isPresent ( this . currentInstruction ) &&
143+ this . currentInstruction . component == instruction . component ;
142144 }
143145
144146
@@ -287,7 +289,7 @@ export class Router {
287289 }
288290
289291 private _canActivate ( nextInstruction : Instruction ) : Promise < boolean > {
290- return canActivateOne ( nextInstruction , this . _currentInstruction ) ;
292+ return canActivateOne ( nextInstruction , this . currentInstruction ) ;
291293 }
292294
293295 private _routerCanDeactivate ( instruction : Instruction ) : Promise < boolean > {
@@ -324,7 +326,7 @@ export class Router {
324326 * Updates this router and all descendant routers according to the given instruction
325327 */
326328 commit ( instruction : Instruction , _skipLocationChange : boolean = false ) : Promise < any > {
327- this . _currentInstruction = instruction ;
329+ this . currentInstruction = instruction ;
328330
329331 var next : Promise < any > = _resolveToTrue ;
330332 if ( isPresent ( this . _outlet ) && isPresent ( instruction . component ) ) {
@@ -403,10 +405,10 @@ export class Router {
403405 }
404406
405407 private _getAncestorInstructions ( ) : Instruction [ ] {
406- var ancestorInstructions = [ this . _currentInstruction ] ;
408+ var ancestorInstructions = [ this . currentInstruction ] ;
407409 var ancestorRouter : Router = this ;
408410 while ( isPresent ( ancestorRouter = ancestorRouter . parent ) ) {
409- ancestorInstructions . unshift ( ancestorRouter . _currentInstruction ) ;
411+ ancestorInstructions . unshift ( ancestorRouter . currentInstruction ) ;
410412 }
411413 return ancestorInstructions ;
412414 }
@@ -443,6 +445,7 @@ export class RootRouter extends Router {
443445 constructor ( registry : RouteRegistry , location : Location ,
444446 @Inject ( ROUTER_PRIMARY_COMPONENT ) primaryComponent : Type ) {
445447 super ( registry , null , primaryComponent ) ;
448+ this . root = this ;
446449 this . _location = location ;
447450 this . _locationSub = this . _location . subscribe ( ( change ) => {
448451 // we call recognize ourselves
@@ -503,7 +506,7 @@ export class RootRouter extends Router {
503506
504507class ChildRouter extends Router {
505508 constructor ( parent : Router , hostComponent ) {
506- super ( parent . registry , parent , hostComponent ) ;
509+ super ( parent . registry , parent , hostComponent , parent . root ) ;
507510 this . parent = parent ;
508511 }
509512
0 commit comments