使用角度2 RC路由器进行编程路线导航的问题

时间:2016-05-24 07:10:07

标签: angular angular2-routing

我从rc1开始使用RC路由器,我有两条路由定义如下:

@Routes([
    {path: '/', component: HomeComponent},
    {path: '/signin', component: SigninComponent},
    {path: '/dashboard', component: DashboardComponent}
])

我试图在退出时导航到'/signin',如下所示:

import {Router} from "@angular/router";

@Component({
    selector: '[signout]',
    templateUrl: 'app/session/session.signout.component.html',
    directives: [CORE_DIRECTIVES],
    pipes: [TranslatePipe]
})
export class SignoutComponent {

    constructor(private router:Router,
                private sessionService:SessionService) {
    }

    signout() {
        this.sessionService.signout();
        //FIXME: does not navigate to '/signin'
        this.router.navigate(['/signin']);
    }

}

但是,当我退出时,浏览器中显示的路径/网址是根网址(/),而不是登录网址...

我错了什么?

1 个答案:

答案 0 :(得分:0)

更改

@Routes([
    {path: '/', component: HomeComponent},
    {path: '/signin', component: SigninComponent},
    {path: '/dashboard', component: DashboardComponent}
])

@Routes([
    {path: '/signin', component: SigninComponent},
    {path: '/dashboard', component: DashboardComponent}
    {path: '/', component: HomeComponent},
])

这是一个已知问题,应该使用下一个版本修复。