Loading

Quipoin Menu

Learn • Practice • Grow

angular / Setting Up Routes
interview

Q1. How do you define a route in Angular?
Routes are defined as an array of objects. Each object has at least path and component. Example:
const routes: Routes = [ { path: ''users'', component: UserListComponent }, { path: ''users/:id'', component: UserDetailComponent } ];
Path can be static or dynamic with parameters.

Q2. What is a redirect route?
A redirect route automatically redirects from one path to another. Example:
{ path: '''', redirectTo: ''/home'', pathMatch: ''full'' }
pathMatch: ''full'' ensures the entire path is matched. ''prefix'' matches the beginning.

Q3. How do you handle wildcard or 404 routes?
Use a wildcard path ''**'' to match any unmatched URL. Place it last. Example:
{ path: ''**'', component: NotFoundComponent }
This catches all invalid routes.

Q4. What is the purpose of pathMatch?
pathMatch determines the matching strategy. ''full'' requires the entire path to match exactly. ''prefix'' matches if the route''s path is a prefix of the URL. For redirects, ''full'' is usually used to avoid accidental matches.

Q5. How do you set up routing in a feature module?
In a feature module, define routes and use forChild. Then import that routing module into the feature module. The main app routing will include a lazy-loaded route pointing to the module, or the feature routes will be merged if the module is eagerly loaded.