I have an Angular2 app that has a module with multiple route parameters, some of which are optional. The routing works completely fine inside Angular itself but generated URLs break if used directly. I'm trying to work out why. I'm also trying to work out how I can get the link to be active when /champion
is access, no matter what the parameters are.
Routes as defined in the module
RouterModule.forChild([
{ path: 'champion/:id', component: ChampionComponent },
{ path: 'champion/:id/:version', component: ChampionComponent }
])
Link (this works when clicked)
<a class="item" [routerLink]="['/champion', 1, '7.9.1']" [routerLinkActive]="['active']" [routerLinkActiveOptions]="{exact:false}">Champion Analysis</a>
But trying to access the URL directly (localhost:5555/champion/1/7.9.1
) fails with Cannot GET /champion/1/7.9.1
EDIT: I should note it is only for the second route that it fails. Typing localhost:5555/champion/1
into the address bar works fine.