Rüdiger Rüdiger - 5 months ago 37
TypeScript Question

Issues upgrading app.component.ts @angular/router and nativescript-angular/router

I am trying to update my NativeScript application. My problems are with the new routing coming up with the upgrade from Angular. My package.json dependency:

"@angular/router": "3.0.0-beta.2"


after upgrading it:

"@angular/router": "4.1.0",


Now I know that there is some new routing and I can't really get into it.

I am struggling updating my app.component.ts.

I cannot figure out how to update the routing, can someone give me a hint?

Answer Source

You don't need to import the directives in app.component.ts.

instead do this:

import {RouterExtensions} from "nativescript-angular";
@Component({
selector: "my-app",
template: "<page-router-outlet></page-router-outlet>"})
export class AppComponent{
constructor(private app : ApplicationService, private router:RouterExtensions ){
this.router.navigate(["/SOME-ROUTE"]);
}

And don't forget to import "NativeScriptRouterModule, NativeScriptRouterModule.forRoot(routes)" in your module.