IT

[angular] redirecting and wildcard

로바아토 2018. 3. 23. 19:14

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.