角度路由在角度 19 中不起作用

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

为什么这个路由配置不起作用?路由器正在尝试访问

/posts
,但不应访问
/posts
。目前它显示一个空白页面。
BlankComponentComponent
包含路由器出口,
FullComponentComponent
包含页眉、路由器出口和页脚。

当用户登录时,应使用

BlankComponentComponent
路由器插座,否则应使用
FullComponentComponent
。我记得我在 Angular 14 中使用过它。

export const routes: Routes = [
  {
    path: '',
    component: BlankComponentComponent, 
    canActivate: [
      () => {
        return true;
      },
    ],
    children: [
      {
        path: '',
        redirectTo: '/auth',
        pathMatch: 'full',
      },
      {
        path: 'auth',
        children: [...authRoutes],
      },
    ],
  },
  {
    path: '',
    component: FullComponentComponent,
    canActivate: [
      () => {
        return false;
      },
    ],
    children: [
      {
        path: '',
        redirectTo: 'posts',
        pathMatch: 'full',
      },
      {
        path: 'posts',
        loadComponent: () =>
          import('./post/posts/posts.component').then((c) => c.PostsComponent),
      },
    ],
  },
];

angular angular-routing angular-router
1个回答
0
投票

can activate 函数返回 false,因此可能无法为帖子加载该组件。

canActivate: [
  () => {
    return true; // <- change this!
  },
],
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.