套路男朋友文件pdf:Angular中的嵌套路由

关于套路男朋友文件pdf的问题,在angular sub router中经常遇到, 这可能是一个常见的问题,如果有更好的答案,请指向我。

这可能是一个常见的问题,如果有更好的答案,请指向我。

在顶层,我正在开发的角度应用程序公开了一个登录路径和路径到 4 个单独的仪表板,具体取决于谁登录。

对于每个仪表板,我都有一个或多或少相同的侧面导航 (某些选项仅针对某些类型的用户显示)。在仪表板中,我有一个嵌套的路由器插座。每当我尝试在嵌套插座内加载模块时,Angular 都无法匹配路径。以下是我到目前为止所拥有的:

app-routing.module.ts

const routes: Routes = [
  { path: '', pathMatch: 'full', redirectTo: 'login' },
  { path: 'login', loadChildren: () => import('./modules/auth/auth.module').then(m => m.AuthModule) },
  //{ path: 'dashboard', loadChildren: () => import('./modules/dashboard/dashboard.module').then(m => m.DashboardModule) }
  { path: 'admin', loadChildren: () => import('./modules/admin/admin.module').then(m => m.AdminModule) },
];

admin-routing.module.ts


const routes: Routes = [
  { path: '', pathMatch: 'full', component: AdminComponent, children: [
    { path: 'employee', loadChildren: () => import('./../employee/employee.module').then(m => m.EmployeeModule) },
    { path: 'attendance', loadChildren: () => import('./../attendance/attendance.module').then(m => m.AttendanceModule) },
    { path: 'customer', loadChildren: () => import('./../customer/customer.module').then(m => m.CustomerModule) },
    { path: 'order', loadChildren: () => import('./../order/order.module').then(m => m.OrderModule) },
    { path: 'expense', loadChildren: () => import('./../expense/expense.module').then(m => m.ExpenseModule) },
  ]},
];

app.component.html

<router-outlet></router-outlet>

admin.component.html

<mat-drawer-container mode="side" id="dashboard-drawer-container" hasBackdrop="false">
  <mat-drawer #drawer id="sidenav-container">
    <app-sidenav></app-sidenav>
  </mat-drawer>
  <div id="dashboard-container">
    <router-outlet></router-outlet>
  </div>
</mat-drawer-container>

现在预期的行为如下:

导航到 / admin 时,将呈现 AdminComponent,并且 sidenav 将可见

单击 sidenav 上的链接时,应在管理组件(例如,admin / employee)中的嵌套路由器中呈现内容

当在 (2) 中加载的模块内访问其他路由时,应在员工详细信息页面的该模块(例如,admin / employee /:id)的出口内呈现该路由,其中,employee 模块具有嵌套路由器

如果我将孩子从管理路由中移出并使他们成为独立的路由,它的工作原理,但是,内容呈现在最外面的(应用程序)路由器出口和 sidenav 不呈现。

任何帮助或建议将不胜感激。

9

让我们把这个问题分解成一个小问题:

应用模块.ts

const routes: Routes = [
  {
    path: '',
    // pathMatch: 'full',
    children: [
      {
        path: 'foo',
        component: FooComponent
      },
    ],
  },
  {
    path: '**',
    component: NotFoundComponent,
  }
];

app.component.html

<router-outlet></router-outlet>
<on routerLink="/foo">go to foo</on>
ng-run demo.

如果我们点击按钮,Angular Router 将安排一个路由转换,这涉及到一个非常有趣的过程,它由多个阶段组成。

其中一个阶段称为应用重定向,它是解决重定向的地方以及NoMatch错误的来源。这也是我们可以找到有关pathMatch: 'full'的更多信息的地方。
在此阶段中,它将遍历每个配置对象,并尝试找到与发布的 URL 匹配的第一个对象(例如2)。

它将首先遇到这个(它发生在matchSegmentAgainstRoute):

{
  path: '',
  // pathMatch: 'full',
  children: [
    {
      path: 'foo',
      component: FooComponent
    },
  ],
},

然后,将调用match函数:

const {matched, consumedSegments, lastChild} = match(rawSegmentGroup, route, segments);

在这里,我们停在route.path === ''

if (route.path === '') {
  if ((route.pathMatch === 'full') && (segmentGroup.hasChildren() || segments.length > 0)) {
    return {matched: false, consumedSegments: [], lastChild: 0, positionalParamSegments: {}};
  }
  return {matched: true, consumedSegments: [], lastChild: 0, positionalParamSegments: {}};
}

所以,这里是一个情况下,pathMatch选项的差异。与当前配置(pathMatch未设置),

return {matched: true, consumedSegments: [], lastChild: 0, positionalParamSegments: {}};

将到达,然后它将继续通过children数组。因此,在这种情况下,FooComponent将成功显示。

但是,如果我们有pathMatch: 'full',那么表达式

if ((route.pathMatch === 'full') && (segmentGroup.hasChildren() || segments.length > 0)) { }

将是true,因为segments.length > 0,在这种情况下,segments 是['foo']。因此,我们将得到matched: false,这意味着FooComponent不会出现在视图中。

0

如果您需要为不同的模块使用不同的 UI,则可以通过在 app-routing.module.ts 中定义父组件来实现。

app-routing.module.ts.

    const routes: Routes = [
      {
        path: '',
        component: AdminComponent, //you can set different UI like navigation/header 
        children: [
         { path: '',redirectTo: 'dashboard',pathMatch: 'full'}, //set default redirect
         { path: 'dashboard', loadChildren: () =>import('./../dashboard/dashboard.module').then(m => m.DashboardModule) },
         { path: 'employee', loadChildren: () => import('./../employee/employee.module').then(m => m.EmployeeModule) },
         { path: 'attendance', loadChildren: () => import('./../attendance/attendance.module').then(m => m.AttendanceModule) },
         { path: 'customer', loadChildren: () => import('./../customer/customer.module').then(m => m.CustomerModule) },
         { path: 'order', loadChildren: () => import('./../order/order.module').then(m => m.OrderModule) },
         { path: 'expense', loadChildren: () => import('./../expense/expense.module').then(m => m.ExpenseModule) },
        ]
      },
      {
        path: '',
        component: AuthComponent, //different UI for child components, without navigation
        children: [
         { path: 'maintenance',loadChildren: () => import('./../maintenance/maintenance.module').then(m => m.MaintenanceModule) },
         { path: 'login',loadChildren () => import('./../authentication/authentication.module').then(m => m.AuthenticationModule) },
         { path: 'landing',loadChildren: () => import('./../landing/landing.module').then(m => m.LandingModule) }
        ]
      }

您的子模块,例如:admin / employee /:id 将呈现父 UI(例如:AdminComponent),

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(238)
Http服务器有哪些:获取 HTTP服务器的服务器头(http server header)
上一篇
少儿编程到底学什么:编程中的综合;它到底是什么(what do synthesis mean)
下一篇

相关推荐

  • html5高级程序设计pdf深入理解新一代Web开发技术

    HTML5高级程序设计PDF是一本关于HTML5的书籍,由Mark Pilgrim撰写。这本书涵盖了HTML5新增的功能,包括新的标签、表单元素、特性、API和CSS3特性。它还深入地介绍了HTML5的语义语法,以及如何使用它来创建可访问的Web应用程序。…

    2023-02-15 12:51:57
    0 69 42
  • Pdf文件:连接PDF文件并将页面插入PDF文件

    关于Pdf文件的问题,在insert page to pdf中经常遇到,我有创建一个 Web 应用程序的新任务(我将使用 Asp.net + C #):• 客户每天给我们 X 个 PDF 文件(x 每天都会有所不同)• 我的应用程序将需要获取此 PDF 文件并在每个 PDF 文件的第 3 页(不是每个 3 页,只是在第 3 页之后)之后插入一个空白页,然后将所有这些 PDF 文件连接到一个大的 PDF 文件中,因为它可以使用它…

    2022-12-25 02:56:25
    0 69 15
  • 取消表格样式:表格的角度样式表(angular material tutorial pdf)

    关于取消表格样式的问题,在angular material tutorial pdf中经常遇到,我按照 Angular 材质教程显示记录表。https://material.angular.io/components/table/overview…

    2022-12-19 10:23:26
    0 86 30
  • 小程序用户服务协议:Angular11:如何在常规ts文件中进行用户服务

    关于小程序用户服务协议的问题,在angular user service中经常遇到,我有一个 utils.ts 文件,其中有一些导出的功能,就像 deepCopy 和 sortArray 或东西,但我想在某些功能中使用服务,我该怎么做?…

    2022-12-20 05:41:27
    0 59 75
  • Angular材质表单字段不工作

    我遵循这个https://material.angular.io/components/form-field/overview,但在我的代码表单字段行为没有改变,标签也没有出现,例如,如果外观是填充它看起来像默认表单…

    2022-11-11 15:21:04
    0 26 80
  • Angular6单元测试:如何使用test.ts运行业力测试

    在我的角 6应用程序,我有这个配置…

    2022-11-11 15:15:25
    0 58 73
  • angular4应用程序在智能电视的网络浏览器(WebOS浏览器 )中不起作用

    我试图在服务器中部署我的 angular4 应用程序,并在桌面浏览器和移动浏览器中正常工作。现在我想从智能电视浏览应用程序,但它显示一个空白页而不是应用程序,可能是什么实际问题在智能电视上浏览我的应用程序?伙计们,如果我需要添加任何依赖项,尤其是智能电视(WebOS 浏览器),请帮助我。…

    2022-11-11 15:14:06
    0 37 66

发表评论

登录 后才能评论

评论列表(54条)