0

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! The export.app.routes should work like this, shouldn't it? Or did I miss something? Edit: could you have a look at my updated code?
@Rüdiger do you have a "root" route? if not, you should add - this.routerExtensions.navigate(["/XXX"]). you don't need to inject "router" itself. use "RouterExtensions" instead for simple navigation (unless you have a good reason to use the basic router)
I update my post for the routes-element. I am not sure if you could use RouterExtensions already in Angular/[email protected], since the application got developed under this. If you could already use it there, it might have a reason that they did not do it (whatever reason that would be)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.