본문 바로가기

IT

[angular] redirecting and wildcard

if there is access from the  path which you don't declare. 

hmm...like localhost:4200/something

it could be error.


You can not cover all other path.

but don't worry, you can use wildcard to solve this problem.

check this code!

const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'users', component: UsersComponent, children: [
{ path: ':id/:name', component: UserComponent }
]},
{ path: 'servers', component: ServersComponent, children: [
{ path: ':id', component: ServerComponent },
{ path: ':id/edit', component: EditServerComponent }
]},
{path: 'not-found', component: PageNotFoundComponent},
{path: '**', redirectTo: '/not-found'}
];


Tip.

{ path: '', redirectTo: '/somewhere-else', pathMatch: 'full' }

we can redirectTo in root path with 'pathMatch' option.

'IT' 카테고리의 다른 글

[angular] authGuard, canActivate, canActivateChild  (0) 2018.03.28
[angular] Outsourcing route config  (0) 2018.03.23
[angular] Handling queryParams  (0) 2018.03.23
[angular] router nested  (0) 2018.03.22
[angular] retrieve the data as number  (0) 2018.03.21