Angular2 Redirect to route on startup
<p>I am making use of <code>@ngrx/store</code> and observables. I have a user reducer that sets information about a user, including a user's JWT.</p>

<p>A <code>NavigationService</code> is injected in to the root <code>AppComponent</code> which subscribes to the <code>user</code> model and will route based upon the presence of a user's token. A <code>UserService</code> reads local storage and will dispatch to the <code>user</code> reducer the result.</p>

<p>The problem is that when I try to route to the home page with <code>goToLogin()</code> I get the error below...which doesn't give much information.</p>

<p>I am guessing that the route components are not set up yet. Is there a way to wait for the application to load before routing? Or does the error below indicate a different issue?</p>

<pre><code>@Injectable()
export class NavigationService {
  private subscription: any;

  constructor(public router:Router, private userService: UserService) {
    this.subscription = this.userService.token$.subscribe(token =&gt; {
       if (token) {
         this.goToSecretStuff();
       } else {
         this.goToLogin();
       }
    });
  }


TypeError: Cannot read property 'constructor' of undefined
    at Object.implementsOnDestroy (pipe_lifecycle_reflector.ts:2)
    at Function.ChangeDetectionUtil.callPipeOnDestroy (change_detection_util.ts:209)
    at AbstractChangeDetector.ChangeDetector_CohortList_0.dehydrateDirectives (viewFactory_CohortList:91)
    at AbstractChangeDetector.dehydrate (abstract_change_detector.ts:177)
    at AbstractChangeDetector.destroyRecursive (abstract_change_detector.ts:200)
    at AbstractChangeDetector.destroyRecursive (abstract_change_detector.ts:207)
    at AbstractChangeDetector.destroyRecursive (abstract_change_detector.ts:207)
    at AppView.destroy (view.ts:159)
    at AppViewManager_.destroyViewInContainer (view_manager.ts:286)
    at ViewContainerRef_.remove (view_container_ref.ts:166)
    at ComponentRef_.dispose [as _dispose] (dynamic_component_loader.ts:283)
    at ComponentRef_.dispose (dynamic_component_loader.ts:87)
    at router_outlet.ts:108
    at e.run (zone-microtask.min.js:8)
    at e.run (ng_zone.ts:371)
    at zone-microtask.min.js:8
    at z (zone-microtask.min.js:8)
    at A (zone-microtask.min.js:8)
    at zone-microtask.min.js:8
    at zone-microtask.min.js:1
    at microtask (ng_zone.ts:410)
    at e.run (zone-microtask.min.js:8)
    at e.run (ng_zone.ts:371)
    at zone-microtask.min.js:8
    at MutationObserver.h (zone-microtask.min.js:8)
</code></pre>