Angular MCQs – Routing and Navigation

21.) What symbol is used to separate query parameters in a URL?

A) #
B) &
C) ?
D) /

Answer: Option C

Explanation: The ? symbol separates the base URL from query parameters, while & separates multiple query parameters.

22.) How do you redirect a user to another route automatically?

A) { path: ”, redirectTo: ‘/dashboard’, pathMatch: ‘full’ }
B) { path: ”, component: DashboardComponent }
C) { path: ”, redirect: ‘/dashboard’ }
D) { path: ”, navigate: ‘/dashboard’ }

Answer: Option A

Explanation: redirectTo automatically redirects users.

23.) How do you navigate back to the previous page using Angular Router?

A) this.router.navigateBack()
B) this.router.goBack()
C) this.router.previous()
D) this.location.back()

Answer: Option D

Explanation: The Location service allows navigation to the previous page using .back().

24.) What does routerLinkActive do?

A) Highlights the active link
B) Disables inactive links
C) Redirects users automatically
D) Caches routes

Answer: Option A

Explanation: The routerLinkActive directive applies a CSS class to the currently active link.

25.) How can you define a default route?

A) { path: ”, component: HomeComponent, pathMatch: ‘full’ }
B) { path: ‘*’, component: HomeComponent }
C) { defaultPath: ‘/’, component: HomeComponent }
D) { redirectTo: ‘/home’ }

Answer: Option A

Explanation: The empty path ” is commonly used for default routes.

26.) What is RouterModule.forRoot(routes) used for?

A) Fetching data from APIs
B) Configuring child routes
C) Defining service dependencies
D) Registering top-level routes

Answer: Option D

Explanation: forRoot() sets up the main application routes.

27.) How do you define routes inside a feature module?

A) RouterModule.forRoot(routes)
B) RouterModule.forChild(routes)
C) RouterModule.define(routes)
D) FeatureModule.configRoutes(routes)

Answer: Option B

Explanation: Feature modules should use forChild() instead of forRoot().

28.) What is the purpose of params in route configuration?

A) To pass dynamic values in a route
B) To create child routes
C) To define default routes
D) To fetch API data

Answer: Option A

Explanation: params allow dynamic routing, useful for fetching data by ID.

Leave a Reply

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