Angular Web Framework Routing & Navigation — Questions and Answers
Question 1: What is the Angular Router?
- A module that maps URL paths to components, enabling single-page application navigation (Correct answer)
- A network router configuration tool
- A server-side request routing system
- A CSS layout grid system
Correct answer: A module that maps URL paths to components, enabling single-page application navigation
The Angular Router maps URL paths to specific components, enabling navigation between different views in a single-page application without full page reloads.
Question 2: What is a route guard in Angular?
- An interface that controls whether navigation to or from a route is allowed (Correct answer)
- A security camera system for physical routes
- A firewall for HTTP requests
- A CSS rule that prevents layout shifts
Correct answer: An interface that controls whether navigation to or from a route is allowed
Route guards (CanActivate, CanDeactivate, CanLoad) are classes implementing specific interfaces that determine whether navigation should proceed, commonly used for authentication and authorization.
Question 3: What are lazy loaded modules?
- Feature modules loaded on demand when their route is first accessed, reducing initial bundle size (Correct answer)
- Modules that load slowly due to performance issues
- Modules that never load completely
- Pre-loaded modules cached in browser memory
Correct answer: Feature modules loaded on demand when their route is first accessed, reducing initial bundle size
Lazy loading defers loading of feature modules until the user navigates to their routes, reducing the initial application bundle size and improving startup performance.
Question 4: What is the ActivatedRoute service?
- A service providing access to route parameters, query parameters, and other route information (Correct answer)
- A service that activates inactive users
- A service for tracking user activity
- A service for managing active database connections
Correct answer: A service providing access to route parameters, query parameters, and other route information
ActivatedRoute provides information about the route associated with the loaded component, including route parameters, query strings, URL fragments, and resolved data.
Question 5: What is the purpose of the router outlet?
- A placeholder directive in the template where routed components are dynamically rendered (Correct answer)
- A power outlet for charging devices
- An output stream for logging
- A CSS container for overflow content
Correct answer: A placeholder directive in the template where routed components are dynamically rendered
The <router-outlet> directive acts as a placeholder in the layout template where the Angular Router dynamically renders the component matching the current URL path.
Question 6: How do you pass parameters in Angular routes?
- Using path parameters (:id), query parameters (?key=value), or route data (Correct answer)
- Parameters cannot be passed in Angular routes
- Only through global variables
- Only through local storage
Correct answer: Using path parameters (:id), query parameters (?key=value), or route data
Angular supports path parameters (/user/:id), query parameters (/search?term=angular), and resolved route data for passing information to routed components.
What is the Angular Router?