Yassmeen Mahmoud Yassmeen Mahmoud - 1 month ago 32
Javascript Question

Angular2 routerLink params

My angular2 app has this routes configuration

export const AppRoutes: Routes = [
{ path: 'SignIn', component: LoginComponent },
{
path: 'Home', component: HomeComponent, canActivate: [LoggedInGuard]
, children: [
{ path: 'ViewUserDetails/:pageTitle', component: ViewUserDetailsComponent },
]
}];


I wanted to use the pageTitle parameter in my component so I passed it in the routerLink this way

<a [routerLink]="['/Home/ViewUserDetails',{pageTitle:'View Channel User'}]">View Channel User</a>


But I get this error


core.umd.js:3257 EXCEPTION: Uncaught (in promise): Error: Cannot match
any routes. URL Segment:
'Home/ViewUserDetails;pageTitle=View%20Channel%20User'


The angular documentation used this to pass parameters I don't understand why it produces this form of the link instead of


/Home/ViewUserDetails/View%20Channel%20User

Answer

Angular 2 router does work on URL fragment base. It navigates between route based on URL pattern.

You should be having just array of expression(here its string).

<a [routerLink]="['/Home/ViewUserDetails','View Channel User']">View Channel User</a>
Comments