What is the purpose of the routes array in Angular?
The routes array defines the paths and their corresponding components for navigation in an Angular app. It tells Angular which component to show when a user visits a specific URL.
Click to reveal answer
beginner
How do you define a simple route for a HomeComponent with path 'home'?
You add an object like { path: 'home', component: HomeComponent } inside the routes array.
Click to reveal answer
beginner
What does the empty string path ('') represent in the routes array?
It represents the default or root path of the app, usually shown when the user visits the base URL.
Click to reveal answer
intermediate
How can you define a route that redirects from one path to another?
Use an object with path, redirectTo, and pathMatch properties, like { path: '', redirectTo: 'home', pathMatch: 'full' }.
Click to reveal answer
intermediate
Why is the order of routes in the routes array important?
Angular matches routes in order. More specific routes should come before less specific ones to avoid incorrect matches.
Click to reveal answer
What property in a route object specifies which component to display?
Apath
BredirectTo
Ccomponent
DloadChildren
✗ Incorrect
The 'component' property tells Angular which component to show for that route.
How do you define a route that redirects from '' to 'home'?
A. redirectTo should be used with pathMatch property.
B. redirectTo cannot be used in routes array.
C. component is missing for 'profile' route.
D. Path 'user' should be capitalized.
Solution
Step 1: Check redirectTo usage
When using redirectTo, Angular requires a pathMatch property to specify matching strategy.
Step 2: Confirm missing pathMatch causes error
Without pathMatch, Angular cannot decide when to redirect, causing routing errors.
Final Answer:
redirectTo should be used with pathMatch property. -> Option A
Quick Check:
redirectTo needs pathMatch [OK]
Hint: Always add pathMatch with redirectTo routes [OK]
Common Mistakes:
Omitting pathMatch with redirectTo
Thinking redirectTo needs component
Assuming path names must be capitalized
5. You want to define routes so that: - The home page shows HomeComponent at path ''. - The about page shows AboutComponent at path 'about'. - Any unknown path redirects to home.