angular - Cannot match children routes of blank path - Stack Overflow

I have this configuration in my routing in Angular:...{path: 'account',canActivate: [AuthGu

I have this configuration in my routing in Angular:

...
{
          path: 'account',
          canActivate: [AuthGuardService],
          children: [
            {
              path: '',
              component: AccountPageComponent,
              outlet: 'modal',
              children: [
                {
                  path: 'pets',
                  component: PetsComponent,
                  children: [
                    {
                      path: ':id',
                      component: PetComponent,
                    }
                  ]
                },
                {
                  path: 'user',
                  component: UserComponent,
                }
              ]
            }
          ]
        }
...

Account route is working as expected and opening in desired outlet. AccountPageComponent has his own nameless outlet for this route children. But when I'm navigating to any of them I'm receiving following errors:

NG04002: Cannot match any routes. URL Segment: 'account/user'

NG04002: Cannot match any routes. URL Segment: 'account/pets'

How can I fix this?

Thanks

I have this configuration in my routing in Angular:

...
{
          path: 'account',
          canActivate: [AuthGuardService],
          children: [
            {
              path: '',
              component: AccountPageComponent,
              outlet: 'modal',
              children: [
                {
                  path: 'pets',
                  component: PetsComponent,
                  children: [
                    {
                      path: ':id',
                      component: PetComponent,
                    }
                  ]
                },
                {
                  path: 'user',
                  component: UserComponent,
                }
              ]
            }
          ]
        }
...

Account route is working as expected and opening in desired outlet. AccountPageComponent has his own nameless outlet for this route children. But when I'm navigating to any of them I'm receiving following errors:

NG04002: Cannot match any routes. URL Segment: 'account/user'

NG04002: Cannot match any routes. URL Segment: 'account/pets'

How can I fix this?

Thanks

Share Improve this question asked Mar 14 at 8:34 Michał BMichał B 5151 gold badge5 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You should navigate using the outlet name - modal:

this.router.navigate(['account', { outlets: { modal: ['pets', '1'] } }]);

this.router.navigate(['account', { outlets: { modal: ['user'] } }]);

In HTML it will be:

<a [routerLink]="['account', { outlets: { modal: ['pets', '1'] } }]">Pet 1</a>
<a [routerLink]="['account', { outlets: { modal: ['user'] } }]">User</a>

The redirection might look like:

{
      path: 'account',
      canActivate: [AuthGuardService],
      children: [
        {
          path: '',
          component: AccountPageComponent,
          outlet: 'modal',
          children: [
            {
              path: 'pets',
              component: PetsComponent,
              children: [
                {
                  path: ':id',
                  component: PetComponent,
                }
              ]
            },
            {
              path: 'user',
              component: UserComponent,
            }
          ]
        },
        {
          path: '/user',
          outlet: 'modal',
          redirectTo: 'user',
          pathMatch: 'full'
        },
        {
          path: '/pets/:id',
          outlet: 'modal',
          redirectTo: (redirectData: any) => {
            return // construct redirect route with params.
          },
          pathMatch: 'full'
        },
      ]
    }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744667531a4586841.html

相关推荐

  • angular - Cannot match children routes of blank path - Stack Overflow

    I have this configuration in my routing in Angular:...{path: 'account',canActivate: [AuthGu

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信