angular2 路由问题
发布时间:2020-12-17 09:21:31 所属栏目:安全 来源:网络整理
导读: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
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 前的斜杠去了就好了,我想问题的原因是因为调用的是子路由,不用出现斜杠吧,这样就尴尬了! 反正问题是解决了解决了 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |