1

I'm following the Angular2 routes tutorial. I'm trying to redirect the default router '' to 'enderecamento' and i got this error on the console: image

My routing code is the following:

app.routing.ts:

export const appRoutingProviders: any[] = [
];

const pecaJuridicaRoutes: Routes = [
  {
    path: '',
    redirectTo: 'pecaJuridica',
    pathMatch: 'full'
  },
  {
    path: 'pecaJuridica',
    component: PecaJuridicaComponent,
    pathMatch: 'full',
    children: [
      { path: 'enderecamento', component: EnderecamentoComponent,},
      { path: '', redirectTo: 'enderecamento', pathMatch: 'full' }
    ]
  },
];
console.log(pecaJuridicaRoutes);


const appRoutes: Routes = [
  ...pecaJuridicaRoutes,
];

export const routing = RouterModule.forRoot(appRoutes);

The strange thing is, if I change:

[...]
children: [
      { path: 'enderecamento', component: EnderecamentoComponent,},
      { path: '', redirectTo: 'enderecamento', pathMatch: 'full' }
    ]
[...]

To this:

[...]
children: [
      { path: 'enderecamento', component: EnderecamentoComponent,},
      { path: '', component: EnderecamentoComponent, }
    ]
[...]

The 'enderecamento' page is loaded, but if iIclick on a routerLink in the page to redirect it or write on the context 'pecaJuridica/enderecamento'i got the same Uncaught promise [object Object] error, is there a way to debug it? It's very frustrating because I know it must be a simple thing, and those error messages aren't intuitive to me..

Some additional info:

Redirection plnkr:

http://plnkr.co/edit/xRu4pS

Redirection routerLink plnkr:

http://plnkr.co/edit/d4xRtw

routerLink html code:

[...]
<ul class="sidebar-nav" id="sidebar">     
                            <li>
                                <a routerLink="enderecamento" routerLinkActive="focus" *ngFor="let button of buttons; let index = index">
                                    <span >{{button.label}}</span>
                                    <span  class="sub_icon glyphicon {{button.class}}" >
                                    </span>
                                </a>
                            </li>
                        </ul>
[...]
Mirza Sisic
  • 2,401
  • 4
  • 24
  • 38
Hllink
  • 918
  • 5
  • 17
  • Where is the routerLink? Have you tried `routerLink="/pecaJuridica/enderecamento"`? – Günter Zöchbauer Aug 23 '16 at 05:15
  • @GünterZöchbauer the routerLink is on the sidebar, a component inside the pecaJuridica component, i tried what you said and it produced the same "uncaught [object Object]" result, i changed one character on the routerLink to force a error and i got the 'Cannot match any routes:' error, so angular do resolve the route, but i don't know why it's not working.. – Hllink Aug 23 '16 at 13:17
  • You could also try `[routerLink]="['/pecaJuridica/enderecamento']"` or ``[routerLink]="['enderecamento']"`. I have seen it mentioned that plain string paths didn't work (might depend on the Angular2/router version you are using) – Günter Zöchbauer Aug 23 '16 at 13:22
  • @GünterZöchbauer im using the "@angular/router": "3.0.0-rc.1", tried it as well and it produced the same result "Error: Uncaught (in promise): [object Object]" – Hllink Aug 23 '16 at 13:35
  • @GünterZöchbauer no problem, thanks for the help ;) – Hllink Aug 23 '16 at 13:39
  • @GünterZöchbauer, added the plnkr's so you can see the errors in real time. – Hllink Aug 23 '16 at 14:41
  • I had a look but wasn't able to figure out what caused the issue. – Günter Zöchbauer Aug 23 '16 at 20:03

0 Answers0