首页 > 解决方案 > Angular 9 - 复杂的子/父导航

问题描述

我完全坚持以下几点。我有一些具有两种不同父布局的路线。

路由.module.ts

{
    path: '',
    component: FrameworkComponent,
    children: [
      {
        path: 'products',
        component: ProductListingPageComponent,
        canActivate: [EnsureAuthenticated]
      },
      {
        path: 'categories',
        component: CategoryListingPageComponent,
        canActivate: [EnsureAuthenticated]
      }
    ]
},
{
    path: '',
    component: AppComponent,
    children: [
      {
        path: 'login',
        component: LoginPageComponent
      },
      {
        path: 'register',
        component: RegistrationPageComponent
      }
    ]
}

因此,在 LoginPageComponents 上,我只想导航到/products路径(以防登录成功)

登录页面.component.ts

this.authService.logIn(this.credentials)
    .then(_ => this.router.navigateByUrl('/products'))
    .catch(this.handleLoginError.bind(this));

结果我什么也得不到。只是一个请求飞到服务器,我看到成功登录,仅此而已 - 没有错误等。

您能否提一些建议?

标签: angularangular2-routingangular-routingangular-routerangular9

解决方案


您是否尝试过检查您收到的回复?

this.authService.logIn(this.credentials)
    .then(res => {
     console.log(res);
     this.router.navigateByUrl('/products');
    }).catch(this.handleLoginError.bind(this));

推荐阅读