简体   繁体   English

如何确定 Angular 路由重定向的来源?

[英]How to determine where an Angular route redirect originates?

I have an Angular 6 SPA.我有一个 Angular 6 SPA。 Periodically, the app performs an action behind the scenes in an iframe (to silently refresh an OAuth token).应用程序会定期在 iframe 中执行幕后操作(以静默方式刷新 OAuth 令牌)。 Each time my app does this, it redirects to the "/" route.每次我的应用程序执行此操作时,它都会重定向到“/”路由。 This is undesirable behavior for the reason that if a user is in the middle of completing a form, he will lose his form and be redirected.这是不受欢迎的行为,因为如果用户正在填写表单,他将丢失表单并被重定向。

I believe that the redirect is happening as a result of something in my code;我相信重定向是由于我的代码中的某些内容而发生的; perhaps a Guard.也许是守卫。 Is there good a way to determine the source of a route redirect in Angular?有没有好的方法可以确定 Angular 中路由重定向的来源?

You can enable debug mode for rouuting in angular using enableTracing您可以使用 enableTracing 启用调试模式以进行角度路由

RouterModule.forRoot(routes, { enableTracing: true })

You will see there is a lot of event running in the app when using routing.使用路由时,您会看到应用程序中运行了很多事件。 So you can do debug more easily.因此,您可以更轻松地进行调试。 Hope that help.希望有所帮助。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM