问题-我在登录页面上,然后单击登录按钮,这应该带我进入工作人员列表页面。但是我被重定向回登录。调试后,我发现它是由于ChildActivationStart而发生的。
因此导航应该作为登录->人员列表 正在作为登录->人员列表->登录(由于附加子路线处理而返回)navigationTrigger对于附加路线“”显示为“ hashchange”
我将NativeScript中的移动应用程序从Angular 4.4升级到了Angular 6.1。发布之后,我发现有些路由问题已经开始发生。在调试它时,我发现问题是由于在路由时添加了新事件ChildActivationStart。
要重现问题的代码,请访问https://play.nativescript.org/?template=play-ng&id=lrIrYT&v=5
这是我的情况
app.routes.ts
export const routes: Routes = [
{ path: "",redirectTo: "authentication", pathMatch: "full" },
{ path: "authentication", component: AuthenticationComponent },
{ path: "staff-list/:id", component: StaffListComponent },
];
在我的AuthenticationComponent中,当我单击登录按钮时,我确实导航到人员列表
export class AuthenticationComponent implements OnInit {
constructor(
private _router: Router
) {}
//on login tap btn
loginTap(args: EventData) {
....
this._router.navigate(['/staff-list']);
}
}
我已启用路由跟踪,这是我发现的日志,如下所示。
JS: Router Event: ActivationEnd
JS: ActivationEnd(path: 'staff-list/:id')
JS: ActivationEnd(path: 'staff-list/:id')
JS: Router Event: ChildActivationEnd
JS: ChildActivationEnd(path: '')
JS: ChildActivationEnd(path: '')
JS: Router Event: NavigationEnd
JS: NavigationEnd(id: 2, url: '/staff-list/10', urlAfterRedirects: '/staff-list/10')
JS: NavigationEnd(id: 2, url: '/staff-list/10', urlAfterRedirects: '/staff-list/10')
JS: Router Event: Scroll
JS: Scroll(anchor: 'null', position: 'null')
JS: Scroll(anchor: 'null', position: 'null')
JS: Router Event: NavigationStart
JS: NavigationStart(id: 3, url: '/authentication')
JS: NavigationStart(id: 3, url: '/authentication')
JS: Router Event: RoutesRecognized
JS: RoutesRecognized(id: 3, url: '/authentication', urlAfterRedirects: '/authentication', state: Route(url:'', path:'') { Route(url:'authentication', path:'authentication') } )
JS: RoutesRecognized(id: 3, url: '/authentication', urlAfterRedirects: '/authentication', state: Route(url:'', path:'') { Route(url:'authentication', path:'authentication') } )
JS: Router Event: GuardsCheckStart
JS: GuardsCheckStart(id: 3, url: '/authentication', urlAfterRedirects: '/authentication', state: Route(url:'', path:'') { Route(url:'authentication', path:'authentication') } )
JS: GuardsCheckStart(id: 3, url: '/authentication', urlAfterRedirects: '/authentication', state: Route(url:'', path:'') { Route(url:'authentication', path:'authentication') } )
JS: Router Event: ChildActivationStart
自ChildActivationStart以来,发生了带有''路由的问题,该路由将其带回到AuthenticationComponent。
在检查为什么升级到Angular 6.x后会发生此行为时,我发现也报告了similar problem,但看不到任何解决方案。当我们没有显式路由到任何子链接时,为什么会发生子路由事件?由于组件位于不同的模块中,是否会出现此问题?我目前拥有的结构是
AppModule
- AuthenticationModule
- StaffModule
但是,所有路由都通过AppModule本身通过app.routes.ts处理。当我再次将Angular降级到4.x版本时,不会出现此问题。那可能是激活ChildRoutes的可能原因吗?