角路由:未捕获(承诺):错误:无法匹配任何路由

时间:2018-09-24 11:30:52

标签: angular routing

我对angular还是很陌生,并且遇到了一个我不理解的问题。

我的路线配置如下

const routes : Route[] = [

{ path: '', pathMatch: 'full', redirectTo: 'sso' },
{ path: 'sso',pathMatch: 'full', loadChildren: './sso/sso.module#SsoModule' },

{
    path: 'auth',
    component: LayoutComponent,
    canActivate : [AuthGuard],
    children: [
        { path: '', redirectTo: 'home', pathMatch: 'full' },
        { path: 'home', pathMatch: 'full', loadChildren: './home/home.module#HomeModule' },

        { path: 'accountService',  loadChildren: './ace/ace.module#AceModule' },



    ]
}, 

{ 
    path: 'auth', 
    component: AceCallbackComponent,
    canActivate : [AuthGuard],
    children: [
        { path: 'accountServiceCallback', loadChildren: './ace/ace.module#AceModule', pathMatch: 'full' }
    ]
},

{ path: 'connect',pathMatch: 'full', loadChildren: './connect/connect.module#ConnectModule' },
{
    path: 'widget',
    component: LandingLayoutPageComponent,
    canActivate : [AuthGuardWidget],
    children: [
        { path: '', redirectTo: 'landing', pathMatch: 'full' },
        { path: 'landing', pathMatch: 'full', loadChildren: './widget/widget.module#WidgetModule' },

    ]

},

最后一个模块是WidgetModule,其路径为“小部件/着陆”

Widget.module:

const routes: Routes = [
  { path: '', component: LandingPageComponent, pathMatch : 'full' },
  { path: 'home', component: LandingPageComponent, pathMatch : 'full' },
];

问题是,当我按下“小工具/着陆”时,它可以工作,但是当我按下“小工具/着陆/家”时,我得到了错误

  

未捕获(承诺):错误:无法匹配任何路线

所有其他路由均正常工作。

有人可以给我一些提示吗?

谢谢

2 个答案:

答案 0 :(得分:0)

将小部件路线更改为以下:

  const routes: Routes = [
       { path: '', component: LandingPageComponent, pathMatch : 'full' },
         children: [
           { path: 'home', component: LandingPageComponent, pathMatch : 'full' }
          ]
     ];

答案 1 :(得分:0)

在您的情况下,router会很困惑,因为您已经为相同组件指定了路径,所以不要在解决方案中尝试此操作,

这是一个例子

const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch : 'full' },
  { path: 'home', component: LandingPageComponent},
];