从另一个父级到命名路由的角路由

问题描述 投票:0回答:2

你如何对待孩子们。

我不熟悉角形,正在尝试构建合适的溃败导航系统到目前为止,我有此溃败:

{path: 'welcome',
  component: WelcomeComponent,
  children: [
    {path: 'login',
      component: LoginComponent,
    outlet: 'welcomeR'},
    {path: 'register',
      component: RegistrationComponent,
      outlet: 'welcomeR'},
    {path: '',
      component: StartComponent
    }
  ]},
  { path: 'user',
    component: UserComponent,
    canActivate: [RoutProtectionService],
    children: [
      {path: '',
        pathMatch: 'full',
      redirectTo: 'profile'},
      {path: 'profile',
       component: ProfileComponent,
        outlet: 'userR'
      },
      { path: 'browseTutors',
        component: TutorsBrowseComponent,
        outlet: 'userR'
      }]
  },
  {path: '**',
  redirectTo: '/welcome'}

您可以从结构中看到,我的应用程序组件中有一个<router outlet>,其中userR / welcomeR路由作为子文件夹。

成功登录后,我想重定向到用户/配置文件组件,但是我不知道该怎么做...如果我正在使用这样的东西:

      this.router.navigate([{outlets: { userR: ['profile']}}] );

它无法匹配任何溃败。如果我导航到['/user'],则不会显示个人资料。我还尝试了类似问题上列出的其他方法,但它们似乎不起作用。例如:

  this.router.navigate(['/user','profile'];

我尝试删除出口:'userR',然后使用'/ user / profile'访问它,但是使用这种方法,不会显示配置文件的内容。

作为替代方案,我还尝试在用户组件的''路径上将重定向设置为'profile',但该方法也不起作用...

angular routing web-deployment angular-router
2个回答
0
投票
我总是使用包含<router-outlet></router-outlet>的baseRouterComponent它是父路由对象。

要重定向,您可以使用router.navigateByUrl("/user")

working example


0
投票
只需确保您具有以下组件中的<router-outlet></router-outlet>AppComponentWelcomeCompoonentUserComponent模板。然后,请勿在路线定义或导航中使用命名的插座。
© www.soinside.com 2019 - 2024. All rights reserved.