Angular Architecture & Modules Quiz – 20 Questions with Answers
20 questions · 15 min · Medium
Test your knowledge of Angular route guards and resolvers, including CanActivate, CanDeactivate, CanMatch, Resolve, route protection, navigation control, and preloading route data.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
B. To control whether navigation to or from a route is allowed
Route guards allow Angular applications to control navigation based on conditions such as authentication or user permissions.
A. CanActivate
CanActivate is used to determine whether navigation to a route can proceed.
B. CanDeactivate
CanDeactivate can be used to determine whether the user is allowed to navigate away from a component, such as when unsaved changes exist.
A. Checking whether a user is authenticated
CanActivate is commonly used to protect routes that should only be accessible to authenticated or authorized users.
A. To load required data before route activation
A resolver retrieves data before the route is activated so the component can receive the required data when it is initialized.
A. Resolve
The Resolve route configuration is used to specify data that should be resolved before route activation.
A. Through the ActivatedRoute data
Resolved route data can be accessed through ActivatedRoute, typically using the route's data or data observable.
B. boolean, UrlTree, or an asynchronous result such as an Observable or Promise of these
Route guards can return boolean or a UrlTree, and they can also return asynchronous values such as Observables or Promises resolving to supported results.
A. Redirect navigation to another route
A guard can return a UrlTree to cancel the current navigation and redirect the user to another route.
A. CanMatch
CanMatch determines whether a route can be matched during route recognition, making it useful for conditional route matching and access control.
A. Preventing navigation when a form contains unsaved changes
CanDeactivate is commonly used to ask the user for confirmation before leaving a page containing unsaved changes.
A. The route can fail to activate
If a resolver's observable or promise errors, navigation can fail unless the error is handled appropriately.
A. Router
The Router service can be used when a guard needs to create a UrlTree or otherwise work with application navigation.
A. A guard controls navigation, while a resolver provides data before route activation
Guards determine whether navigation can proceed, whereas resolvers are intended to obtain route data before the component is activated.
A. Fetching a user's profile before displaying the profile page
A resolver is useful when a route depends on data that should be loaded before the component is activated.