This.router.navigate does not call component constructor


#1

I am following angular2-meteor socially tutorial. I noticed that this.router.navigate("/someRoute"); navigate to that url but does not call constructor of that component and also its template does not get rendered. Does anyone know the solution?
@Hongbo_Miao do you about this issue? Also I noticed that in @RouteConfig “as” does not work anymore. We have to use “name” instead.


#2

UPDATED: Now recommend using v3 router.

Note the tutorial is using deprecated router.
Are you using v3 router? If so, hope someone else can help you right now. Because I haven’t tried v3 router yet. I am using ngrx/router now. But I will switch to v3 router when I feel it is more stable.


#3

Here is my package.json
"dependencies": {
"@angular/common": “^2.0.0-rc.1”,
"@angular/core": “^2.0.0-rc.1”,
"@angular/platform-browser": “^2.0.0-rc.1”,
"@angular/platform-browser-dynamic": “^2.0.0-rc.1”,
"@angular/router-deprecated": “^2.0.0-rc.1”,
“angular2-meteor”: “^0.5.5”,
“angular2-meteor-accounts-ui”: “^0.4.3”,
“angular2-meteor-auto-bootstrap”: “^0.5.5”,
“es6-shim”: “^0.35.0”,
“meteor-node-stubs”: “^0.2.3”,
“reflect-metadata”: “=0.1.2”,
“rxjs”: “=5.0.0-beta.6”,
“zone.js”: “^0.6.12”
}


#4

Can you share the skeleton of your project with ngrx router? Just main and possibly one route?


#6

Badly articulated on my side. I am starting a new angular2 meteor project,
and I want to use ngrx router. I am looking for some sort of a seed
project. Right now could not get it going yet.


#7

UPDATED: Now recommend using v3 router.

Oh, hmm the reason I am using ngrx/router is because I am using with ngrx/store and other Redux things.

And the reason I will finally switch to v3 router is because v3 router is redesigned based on ngrx/router.

Also, ngrx/router is not complete, such as it does not have routerCanDeactivate (link to the issue).

And it will probably never have. Because people who created this router will switch their focus on v3 router.


So just stay with router that you are using now a little while. Start to use v3 router when it is more stable and complete.


#8

If you plan to start from ngrx/router, their document is really well-written.

When I start to learn, I just read through them, and then use it.

And here is the plunker.


#9

Most time your page does not render is because you call this.router.navigate("/someRoute"); out of angular 2 zone, you need run it inside of zone to update UI immediately.

Try to add this part.

import { NgZone } from '@angular/core';

constructor(private _ngZone: NgZone) {}

this._ngZone.run(() => {
  this.router.navigate("/someRoute");
});

#10

Thanks for the tips! I am following your advice and staying with the angular-router (the v3, not sure anymore how it should be correctly called…). I did realize that it is a migration from ngrx/router, with some modifications.
Plunker is also good, but I am looking into a meteor-angular2 version. I am taking socially app and moving it to router v3 and see if that works.
No doubt that between the Angular2 rc2/3 upgrade, the Meteor 1.3.3 and the new router, the life of the angular meteor programmers is less than ideal at the moment.


#11

For other people, check this for explanation and some clean way