Angular 2无法通过url加载子路由

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

我已经定义了子路由,但我无法从url栏手动导航到这些路由。当我输入完整的URL时,它会回到第一个子路径;我错过了什么吗?

   {
  path: 'config',
  component: ConfigComponent,
  children: [
    { path: 'wordlists', component: WordListComponent },
    { path: 'groups',  component: GroupBuilderComponent },
    { path: 'tagbuilder', component: TagBuilderComponent }
  ],
  canActivate: [RouteGuard],
  data: { allowed: ['inv'] }
   }

当我输入网址http://localhost:63020/portal/config/tagbuilder时,它总是带我到http://localhost:63020/portal/config/wordlists

如何通过URL访问每个子路由?

这是尝试导航到tagbuilder时的控制台日志,但跳回enter image description here

angular url angular-router
1个回答
1
投票

发现问题,我在ngOnInit中有方法导致页面在初始化时始终加载到Wordlists页面上。因此,当我输入url时,它首先在ngOnInit中触发该函数,限制转到其他url,一旦我删除了该函数,我就能够分别访问每个路径

© www.soinside.com 2019 - 2024. All rights reserved.