Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'main'
这个问题的处理很简单,是路由的路径写错了,
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 = [ {path:'login',component:loginComponent},{path:'index',component:indexComponent,children:[ {path:"main",component:mainComponent},{path:'',redirectTo:'/main',pathMatch:'full'} ]},redirectTo:'/index',pathMatch:'full'} ]; @NgModule({ imports: [RouterModule.forRoot(routes)],exports: [RouterModule],}) export class MyRoutingModule { }
我的情况是在父组件中调用子路由的时候,出现这个问题的,大家只需要更改一个地方,
{path:'',redirectTo:'main',pathMatch:'full'}
把main 前的斜杠去了就好了,我想问题的原因是因为调用的是子路由,不用出现斜杠吧,这样就尴尬了!
原文链接:https://www.f2er.com/angularjs/147412.html