I am having some trouble with my angular router, I keep getting this error and I know it is something very basic, but I don't have much experience with angular, thus I am asking for your help:
my html link:
<a href="" routerLink="/work-groups" routerLinkActive="active">Work Groups</a>
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { MatDialogModule } from '@angular/material/dialog';
import { MatCardModule } from '@angular/material/card';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input'
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app.routes'
import { CreateWorkerComponent } from './component/create-worker/create-worker.component';
import { MaintainWorkGroupComponent } from './component/maintain-work-group/maintain-work-group.component';
import { Session } from './model/entity/Session';
import { ListWorkGroupComponent } from './component/list-work-group/list-work-group.component';
import { ItemWorkGroupComponent } from './component/item-work-group/item-work-group.component';
import { DashboardComponent } from './component/dashboard/dashboard.component';
@NgModule({
declarations: [
AppComponent,
CreateWorkerComponent,
MaintainWorkGroupComponent,
ListWorkGroupComponent,
ItemWorkGroupComponent,
DashboardComponent
],
imports: [
BrowserModule,
FormsModule,
HttpClientModule,
MatDialogModule,
MatCardModule,
MatButtonModule,
MatFormFieldModule,
MatInputModule,
AppRoutingModule
],
providers: [
Session,
AppComponent,
ItemWorkGroupComponent,
MaintainWorkGroupComponent
],
bootstrap: [AppComponent],
entryComponents: [
ItemWorkGroupComponent,
MaintainWorkGroupComponent
]
})
export class AppModule { }
app.routing.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router'
import { DashboardComponent } from './component/dashboard/dashboard.component';
import { ListWorkGroupComponent } from './component/list-work-group/list-work-group.component';
const ROUTES: Routes = [
{ path: '', component: DashboardComponent },
{ path: '/work-groups', component: ListWorkGroupComponent }
]
@NgModule({
imports: [RouterModule.forRoot(ROUTES)],
exports: [RouterModule]
})
export class AppRoutingModule { }
I have also tried to export my routes as a constant and use it in my app.module.ts
but it did not work as well.
I really do not know what I am missing, please if you need more info just let me know.
Thanks in advance!
CodePudding user response:
Remove the preceding forward slash from the route:
const ROUTES: Routes = [
{ path: '', component: DashboardComponent },
{ path: 'work-groups', component: ListWorkGroupComponent } <== SEE HERE
]