angular2 routing problem

angular2 routing problem

Uncaught (in promise): Error: Cannot match any routes. URL Segment:'main'

The handling of this problem is very simple, the route path is wrong,

import {NgModule} from'@angular/core';
import {Routes, RouterModule} from'@angular/router';
import {loginComponent} from'./login/login.component';
import{indexComponent} from "./index/index.component";
import {mainComponent} from "./main/main.component";
const routes: Routes = [

  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
export class MyRoutingModule {}

In my case, this problem occurred when the child route was called in the parent component. You only need to change one place.


Just remove the slash before main. I think the reason for the problem is that the sub-route is called, so there is no need for a slash, which is embarrassing!

Anyway, the problem is solved

Reference: angular2 routing problem-cloud + community-Tencent Cloud