Error: Cannot match any routes. URL Segment: 'login'

前端 未结 1 1326
-上瘾入骨i
-上瘾入骨i 2021-01-29 04:54

my page http: // localhost:4200 load correctly, but when i want to go to the link http: // localhost: 4200 /login it return to the link http: // localhost: 4200 and show error.<

1条回答
  •  滥情空心
    2021-01-29 05:31

    This is because you are declaring routes in the app.module.ts as well as routing-module.module.ts. Declare all your routes in the routing module instead. You can use @angular/cli to generate your routing module so it's created with a better name. If you create it using cli commands, set the name as routing as Angular will already add module for you. explicity adding module to your name will give you the redudant Module word in your class name (RoutingModuleModule).

    Remove the routes created in your app.module.ts and import RoutingModule (or RoutingModuleModule in your case)

    imports: [
      BrowserModule,
      RoutingModuleModule
    ]
    

    Move the route from your app.module.ts to your routing.module.ts

    const routes: Routes = [
       { path: '' , redirectTo: '/task', pathMatch: 'full' }
       { path: 'login', component: LoginComponent },
       { path: 'task' , component: TaskManagerComponent }
    ];
    

    0 讨论(0)
提交回复
热议问题