Wie die call-router-navigate-Methode aus dem Winkel 2?

Verwende ich Winkel 2, SystemJs und ES6 (Nicht Typoskript).

Was will ich? Ich will navigieren Sie zum link mit der Route. Was mache ich

//route for exam simple
export let routes = [
    {path: '', name: 'home', component: HomeComponent, terminal: true}, 
    {path: 'auth', name: 'auth', component: AuthComponent}
]

Funktioniert es auch wenn ich mit [routerLink]. Und jetzt will ich programmatisch router verwenden, wie dies

    import { Component } from '@angular/core';
import { Router, ROUTER_DIRECTIVES } from '@angular/router';

@Component({
    selector: 'tf-main',
    directives: [ROUTER_DIRECTIVES],
    template: '<p>home</p><router-outlet></router-outlet>'
})

export class HomeComponent {

    static get parameters() {
        return [[Router]]
    }

    constructor(router) {
        this.router = router;

        //This wrong way!!!! Help!!!!
        this.router.navigateByUrl(['auth']);
    }
}

InformationsquelleAutor Kirill Muchow | 2016-07-04

Schreibe einen Kommentar