首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >角多模选路

角多模选路
EN

Stack Overflow用户
提问于 2017-06-12 20:09:18
回答 1查看 506关注 0票数 1

我必须使用模块,在这些模块中,在通过auth进行路由的过程中,the模块是延迟加载的。具有路由的主模块app模块如下所示:

代码语言:javascript
运行
复制
const app_routes: Routes = [
  { path: '', component: MainComponent, outlet: 'app', pathMatch: 'full', 
  canActivate: [OauthGuard]},
  { path: 'auth', loadChildren: 'app/authentication/authentication.module#AuthenticationModule'},
  { path: '**', component: PageNotFoundComponent, outlet: 'app' }
];

@NgModule({
  declarations: [...],
  imports: [RouterModule.forRoot(app_routes)],
  providers: [OauthGuard],
 bootstrap: [
   AppComponent
 ],
 schemas: [CUSTOM_ELEMENTS_SCHEMA],
 exports: [RouterModule]
})
export class AppModule {}

在这里,导航到auth加载AuthenticationModule

代码语言:javascript
运行
复制
const auth_routes: Routes = [
  {
    path: '',
    component: AuthenticationComponent,
    outlet: 'app',
    children: [
      { path: '', redirectTo: 'login', pathMatch: 'full' },
      {
        path: 'register',
        component: RegisterComponent,
        outlet: 'auth'
      },
      {
        path: 'login',
        component: LoginComponent,
        outlet: 'auth'
      }
    ]}
];

@NgModule({
  imports: [
    CommonModule,
    RouterModule.forChild(auth_routes),
    UtilsModule,
    HttpModule
  ],
  declarations: [
    AuthenticationComponent,
    RegisterComponent,
    LoginComponent
  ],
  exports: [
    RouterModule
  ],
  providers: [
    ClientService,
    AuthenticationService
  ],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  bootstrap: [
    AuthenticationComponent
  ]
})

export class AuthenticationModule {
}

根据我的逻辑,当导航到LoginComponent时,auth应该被加载到auth/login路由器-出口上.但相反,我得到了以下错误消息:

错误:无法匹配任何路由。URL段:‘auth/登录’

正如建议的那样,当canActivate()在第一次路由更改时被调用时,我记录了已注册的路由,得到了以下结果:

代码语言:javascript
运行
复制
Routes:  [
  {
    "path": "",
    "outlet": "app",
    "pathMatch": "full",
    "canActivate": [
      null
    ]
  },
  {
    "path": "auth",
    "loadChildren": "app/authentication/authentication.module#AuthenticationModule"
  },
  {
    "path": "**",
    "outlet": "app"
  }
]

注册的路由在àuthentication.module`构造函数的ran中是相同的。

我真的不知道为什么我还会犯这个错误。有小费吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-14 09:39:11

在一些帮助下,我解决了这个问题,那里的问题是出口名称。我不知道有可能有多个未命名的router-outlets,只要它们属于不同的作用域。所以我所做的只是删除插座的名字。使用我的旧代码,我必须导航到/auth(auth:login),其中(auth:login)指定要显示的出口名称和子路由。没有出口名称,我可以简单地导航到auth/login,并到达所需的页面。

authentication.module

代码语言:javascript
运行
复制
const routes: Routes = [
  {
    path: '',
    component: AuthenticationComponent,
    children: [
      { path: '', redirectTo: 'login', pathMatch: 'full'},
      {
        path: 'register',
        component: RegisterComponent
      },
      {
        path: 'login',
        component: LoginComponent
      }
    ]}
];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44507914

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档