I followed a video tutorial to write this code, but it's not working as expected and is throwing some errors. Is it possible that the tutorial is outdated and using an older methodology? The code seems to be hard-coded without using any services.
Here is the code from app-routing.module.ts:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { DepartmentListComponent } from './department-list/department-list.component';
import { EmployeeListComponent } from './employee-list/employee-list.component';
const routes: Routes = [
{ path: 'departments', component: DepartmentListComponent },
{ path: 'employees', component: EmployeeListComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
export const routingComponents [DepartmentListComponent, EmployeeListComponent ]
And here is the code from app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule, routingComponents } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent,
routingComponents
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
In app.component.html:
<h1> Welcome to the Routing Example</h1>
<router-outlet></router-outlet>
I am a beginner and would appreciate any help in running the application with URLs changing to http://localhost:4200/employees and http://localhost:4200/departments. Thank you for your understanding.