Bird
0
0

Identify the error in this RouterModule configuration:

medium📝 Debug Q14 of 15
Angular - Routing
Identify the error in this RouterModule configuration:
const routes = [
  { path: 'home', component: HomeComponent },
  { path: 'profile' component: ProfileComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule {}
ARoutes array should be inside imports array
BRouterModule.forRoot should be RouterModule.forChild
CAppRoutingModule should not export RouterModule
DMissing comma between 'profile' path and component property
Step-by-Step Solution
Solution:
  1. Step 1: Check routes array syntax

    Between 'path: 'profile'' and 'component: ProfileComponent' a comma is missing, causing syntax error.
  2. Step 2: Verify RouterModule usage and exports

    Using RouterModule.forRoot(routes) and exporting RouterModule is correct here.
  3. Final Answer:

    Missing comma between 'profile' path and component property -> Option D
  4. Quick Check:

    Comma missing in object properties causes error [OK]
Quick Trick: Check commas between object properties in routes [OK]
Common Mistakes:
MISTAKES
  • Confusing forRoot and forChild usage
  • Placing routes array incorrectly
  • Removing exports of RouterModule

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes