angular icon indicating copy to clipboard operation
angular copied to clipboard

Can't use routerLink w/o a explicit route config (even if routes are defined in the app component)

Open chalin opened this issue 10 years ago • 3 comments

The Tour-of-Heroes tutorial part 5 is an app with a dashboard and a heroes view. We're trying to switch over to using routerLink's in the dashboard. RouterLinks are already used in the app template. When I try to use a routerLink in the dashboard template I get the error:

Uncaught Unhandled exception: Component "DashboardComponent" has no route config.

The only routes in the app are those defined in the app_component. The dashboard defines no routes itself. If I try to add an empty @RouteConfig(const []) then I get an error about child routes.

This problem is illustrate in the code changes in PR https://github.com/angular/angular.io/pull/2744.

cc @kwalrath

chalin avatar Nov 08 '16 18:11 chalin

Probably you have to remove at the string ./HeroDetail part ./ (two beginning chars). But for me It led to another "Invalid argument" exception. ...some time later... And then, I guess, you shouldn't use converting 'string' to 'int' (int.parse(idString ?? '', onError: (_) => null)), because It issues the exception due to idString is already Int. Thus invocation of the method toString() at the implementation of gotoDetail() not needed. OMG

arshvin avatar Nov 13 '16 11:11 arshvin

@matanlurey - any update on this? I'd like to wrap up the new router chapter soon and it would be nice to have this resolved before then.

cc @kwalrath @filiph

chalin avatar Nov 19 '16 21:11 chalin

@arshvin, you were right about the router name; either /, ../ or nothing is correct, but (now in retrospect), it is obvious that './' is not. As for the typing issue, the fix was to further tweak the router link to be:

[routerLink]="['HeroDetail', {id: hero.id.toString()}]"

Notice the toString() call on hero.id.

@matanlurey - I've created #203 and #204 as followup issues.

chalin avatar Nov 21 '16 13:11 chalin