Angular MCQs – Routing and Navigation

11.) What is the purpose of the pathMatch: ‘full’ property in a route?

A) It redirects the user to an external URL
B) It enables child routes
C) It activates lazy loading
D) It ensures only exact matches are used for navigation

Answer: Option D

Explanation: When using redirectTo, the pathMatch: ‘full’ ensures that the path must match exactly before the redirection happens.

12.) What is a child route in Angular?

A) A route that is lazy-loaded
B) A sub-route inside a parent route
C) A secondary navigation option
D) A duplicate route

Answer: Option B

Explanation: Child routes allow you to define nested views, useful for complex UIs with multiple levels of navigation.

13.) How do you define a child route in Angular?

A) Using the children property inside a route
B) Using Router.forChild()
C) Using nestedRoutes: []
D) Using subRoutes: []

Answer: Option A

Explanation: Child routes are defined using the children property within a parent route configuration.

14.) Which route guard is used to prevent unauthorized access to routes?

A) CanLoad
B) CanActivate
C) CanDeactivate
D) Resolve

Answer: Option B

Explanation: CanActivate prevents unauthorized users from accessing certain routes.

15.) What is the purpose of the CanDeactivate route guard?

A) It prevents unauthorized access
B) It allows lazy loading
C) It asks for confirmation before leaving a route
D) It handles wildcard routes

Answer: Option C

Explanation: CanDeactivate prompts users before leaving a route, useful for unsaved changes warnings.

16.) What is lazy loading in Angular routing?

A) Loading JavaScript files dynamically
B) Loading components only when needed
C) Loading routes based on user permissions
D) Caching API responses

Answer: Option B

Explanation: Lazy loading improves performance by loading feature modules only when they are accessed.

17.) What method is used to listen for route changes?

A) router.events.subscribe()
B) router.change()
C) router.update()
D) router.onRouteChange()

Answer: Option A

Explanation: The Router service emits route change events using .events.subscribe().

18.) What is the main advantage of lazy loading?

A) Prevents route navigation
B) Increases loading time
C) Reduces the initial bundle size
D) Improves form validation

Answer: Option C

Explanation: Lazy loading helps optimize performance by loading only necessary modules on demand.

19.) What is a resolver in Angular routing?

A) A function that delays navigation
B) A service that pre-fetches data before a route is activated
C) A way to prevent unauthorized access
D) A built-in Angular directive

Answer: Option B

Explanation: Resolve guards help fetch data before navigation, ensuring data is ready before the component loads.

20.) How do you retrieve query parameters in Angular?

A) Using ActivatedRoute.snapshot.queryParams
B) Using Router.navigate()
C) Using getQueryParams()
D) Using ActivatedRoute.params

Answer: Option A

Explanation: Query parameters can be accessed using ActivatedRoute.snapshot.queryParams or ActivatedRoute.queryParams.

Leave a Reply

Your email address will not be published. Required fields are marked *