angular2 路由问题

2018-06-15 12:22:59 浏览数 (1)

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

这个问题的处理很简单,是路由的路径写错了,

代码语言:javascript复制
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'}
   ]},
 {path:'',redirectTo:'/index',pathMatch:'full'}
];

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

我的情况是在父组件中调用子路由的时候,出现这个问题的,大家只需要更改一个地方,

{path:'',redirectTo:'main',pathMatch:'full'}

把main 前的斜杠去了就好了,我想问题的原因是因为调用的是子路由,不用出现斜杠吧,这样就尴尬了!

反正问题是解决了解决了

0 人点赞