Angular 如何检查路由子级是否存在-角度

Angular 如何检查路由子级是否存在-角度,angular,routing,Angular,Routing,我试图重定向用户,如果他移动到错误的子路径。我已经为一个子组件创建了防护,该子组件正在向api请求数据,但我不确定如果数据不存在,如何重定向用户。如果数据不存在或重定向到主页,我想为用户显示404。抱歉,如果重复,但我无法找到解决方案 情景: 用户必须传递密码才能重定向到他的电影。(授权服务) 如果通过,用户将重定向到其路由页面和数据的保护请求(保护) 比如说。我有2个用户[John,Rick](“/strefa klienta/John”)。如果有人试图找到一个不存在“Anna”(“/stre

我试图重定向用户,如果他移动到错误的子路径。我已经为一个子组件创建了防护,该子组件正在向api请求数据,但我不确定如果数据不存在,如何重定向用户。如果数据不存在或重定向到主页,我想为用户显示404。抱歉,如果重复,但我无法找到解决方案

情景:

  • 用户必须传递密码才能重定向到他的电影。(授权服务)
  • 如果通过,用户将重定向到其路由页面和数据的保护请求(保护)
  • 比如说。我有2个用户[John,Rick](“/strefa klienta/John”)。如果有人试图找到一个不存在“Anna”(“/strefa klienta/Anna”)的用户,我想显示404


    感谢您的帮助

    我认为您必须将此添加到app-routing.module中

    
    {
       path: "strefa-klienta",
       children: [
         {
           path: "",
           pathMatch: "full",
           redirectTo: "/"
         },
         {
           path: ":id",
           component: components.ClientSiteComponent,
           canActivate: [guards.ClientGuard]
         },
       ],
    }
    
    { path: '', redirectTo: 'home', pathMatch: 'full' },
    { path: '**', redirectTo: 'home', pathMatch: 'full' }
    

    我以前试过,但没什么改变。在路径中,我可以写入随机参数,它仍然会路由。(/strefa klienta/example_text)。
    
    {
       path: "strefa-klienta",
       children: [
         {
           path: "",
           pathMatch: "full",
           redirectTo: "/"
         },
         {
           path: ":id",
           component: components.ClientSiteComponent,
           canActivate: [guards.ClientGuard]
         },
       ],
    }
    
    { path: '', redirectTo: 'home', pathMatch: 'full' },
    { path: '**', redirectTo: 'home', pathMatch: 'full' }