我目前正在尝试将一个angularjs方法转换为角度 . 在angularjs中,我使用ui-router事件处理来为我的路由做一些重定向,以避免在页面重新加载或深度链接导航时进行解析和状态更改 . 在angularjs中,我向一些状态添加了一系列所需的功能,然后使用该数据来决定在转换时是否需要重定向 . ui-router状态层次结构也允许遵循父母的要求 .

我试图在angular6 atm中使用本机路由器做同样的事情,但面临一个问题 - 甚至无法从处理中获得路由配置 .

const routes: Routes = [
  { path: '', redirectTo: 'login', pathMatch: 'full' },
  { path: 'login', component: LoginComponent, data: { req: { auth: false } } },
  { path: 'home',
    component: HomeLayoutComponent,
    data: { req: { auth: true } },
    children: [
      { path: '', pathMatch: 'full', redirectTo: '/home/(content:roles)' },
      { path: 'roles', component: RolesComponent, outlet: 'content' },
      { path: 'pro', component: ProComponent, outlet: 'content' },
    ]
  }
];

这是我的示例路由配置 . 我想得到的是,如果用户导航到“登录”路线,那么我检查路线的配置,看看认证应该是假的,如果不是 - 重定向到家 .

我有路由器事件的事件处理程序

export class AppComponent implements OnInit {
  title = 'app';
  constructor ( private _core: EngineService, private router: Router ) { }
  ngOnInit() {
    this.router.events.subscribe((event) => {
        console.log(event, this.router);
      });
  }

但是,我得到的是:

RoutesRecognized {id: 1, url: "/", urlAfterRedirects: "/login", state: RouterStateSnapshot}

只有url我无法可靠地将其映射到router.config . 我在这个问题上看了很多关于SO的问题,但所有问题都是关于获取网址的 . 有关如何获取实际配置参考的任何建议?