Melchior_
Melchior_

Reputation: 75

Route blank to child component with id

I expect www.mypage.com/users to be routed to www.mypage.com/users/1, how can this be achieved?

I tried following

 path: 'users', redirectTo: '1', pathMatch: 'full', children: [     
  { path: ':id', component: UsersComponent }
]

I could also return 404 page but thats not what I want.

Upvotes: 1

Views: 103

Answers (2)

Pankaj Parkar
Pankaj Parkar

Reputation: 136184

This can be done by using adding one more child route with ''(blank) path check inside child route. But you have to create an parent component which template would have router-outlet once again.

{
  path: 'users', component: UserWrapperComponent, 
    children: [
       { path: '', redirectTo: '1', pathMatch: 'full' }
       { path: ':id', component: UsersComponent }
    ]
}

Upvotes: 2

Malindu Sandaruwan
Malindu Sandaruwan

Reputation: 1517

Try this,

{path: 'users', redirectTo: 'users/1', pathMatch: 'full', children: [     
  { path: '1', component: UsersComponent }
]

Upvotes: 0

Related Questions