【问题标题】:angular nested categories refresh router problem角度嵌套类别刷新路由器问题
【发布时间】:2020-07-06 01:38:25
【问题描述】:

我有一个如下所示的模块:

categories-routing.module.ts*

const routes: Routes = [
  { path: '', component: CategoriesComponent }, // this path does not reload
  { path: 'new', component: CategoryFormComponent, canActivate: [AuthGuard, EmailGuard] },
  { path: 'edit/:id', component: CategoryFormComponent, canActivate: [AuthGuard, EmailGuard] },
  {
    path: 'category', redirectTo: '',
    children: [
      {
        path: '**',
        component: CategoriesComponent
      }
    ]
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class CategoriesRoutingModule { }

还有categories.component.ts

@Component({
  selector: 'app-categories',
  templateUrl: './categories.component.html',
  styleUrls: ['./categories.component.scss']
})
export class CategoriesComponent {

  public categories!: Observable<any>;

  constructor(
    private nav: NavbarService,
    public cs: CategoryService,
    private route: ActivatedRoute,
    private router: Router
  ) {
    this.router.routeReuseStrategy.shouldReuseRoute = () => false;
  }

  ngOnInit() {
    this.categories = this.route.data.pipe(
      switchMap(() => {
        return this.cs.loadCategories();
      })
    );
  }

浏览目录工作正常,但是,当我转到“”路径时,它不会重新加载,只显示最后一个路径。我已经尝试以许多不同的方式订阅激活的路线等以获得完全相同的结果。我也希望重新加载组件,而不是页面。

【问题讨论】:

    标签: angular categories router reload angular9


    【解决方案1】:

    所以事实证明我的 loadCategories() 函数中有一些错误的逻辑。至少两天的研究让我了解了更多关于路由器的知识!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-17
      • 2018-07-21
      • 2019-01-06
      • 2018-10-12
      • 2016-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多