组件导航路线

时间:2016-05-24 18:03:05

标签: angularjs angular angularjs-components angular-component-router

如何从当前组件导航到另一个组件?我试过这样的:

帐户组件:

vm.$onInit = function () {
    var jwt = accountService.getJWT();

    if (!jwt || jwtHelper.isTokenExpired(jwt)) {
        this.$router.navigate(['registration']);
    }
};

这对我不起作用:(

Component "Root" has no route config.

我设置了$ routerRootComponent

.value('$routerRootComponent', 'app')
.component('app', {
    template: '<ng-outlet></ng-outlet>',
    $routeConfig: [
        {path: '/registration', component: 'registration', useAsDefault: true},
        {path: '/registration/:referrer', component: 'registration'},

        {path: '/account', component: 'account'}
    ]
})

plnkr

1 个答案:

答案 0 :(得分:1)

路由(在旧路由器中)需要一个名称,而router.navigate()需要使用该名称,否则您需要使用例如router.navigateByUrl()

xorWith()