2

How to naviage to another component from current component? I have tried like this:

account component:

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

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

This doesn't work for me :(

Component "Root" has no route config.

I have set $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

  • More information would be helpful. What and where is "another component" and what and where is "current component". How is this related to Angularjs? Looks like an Angular2 question. – Günter Zöchbauer May 25 '16 at 06:01
  • I'm trying to change current location (account component) to another component (for example registration component). – Mikhail Makarov May 25 '16 at 06:49
  • Thats the same "info" your question contains and doesn't provide additional information. For routing it relevant if where routes are added (root component, child component, component with or without ``) and where the component is (again root component, child component, ...) that contains the `this.$router.navigate(...)` code. Without this information there is not much one can suggest. It might be necessary to create a Plunker that allows to reproduce the problem. – Günter Zöchbauer May 25 '16 at 06:52
  • Sorry... it's my one of the first experience to make questions here. http://plnkr.co/edit/tvarryG8ykZTGyfXK2cl?p=preview is plnkr with reproduction my problem. – Mikhail Makarov May 25 '16 at 10:40

1 Answers1

1

Routes (in the old router) need a name and router.navigate() expects the name to be used, otherwise you would need to use for example router.navigateByUrl().

Plunker example

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567