Blazor Server:导航到其他页面后,NavigationManager停止页面
带有“ Page1”,“ Page2”,“ Page3”,“ Pagex”菜单项的自定义菜单组件的julazor。 单击“ Page1”时,我使用NavigationManager导航到其他页面。
这一切都很好。
但是,当我快速单击“ page1”,“ page2”或2个或更多页的其他组合时,我有一个问题,即我的页面加载了,但直接加载了另一页,因为我迅速单击了菜单项。 我的页面包含异步/等待方法,在这里我遇到了一个问题:
- 快速单击“ page3”,单击“ page1”,单击“ page2”
- 导航到“ page3”
- ynnc方法中的“ page3” ynk in in in of page3启动(使用async/agait/events附加/...)
- 突然导航发生到“ Page1”
- 大麻应用程序崩溃,因为例如,异步任务返回数据或从“ Page3”访问组件,该组件已经被处置了,因为我们导航到“ Page1”,
- 如果我们很幸运,到达“ Page1”,但可能会发生同样的原因,因为当导航发生时直接发生“ Page2”的导航
,是否有一种方法可以在导航到其他页面时“取消”当前页面? (例如,也许类似于取消词?)
Blazor with a custom menu component having "Page1", "Page2", "Page3, "PageX" menu items.
When clicking "Page1" I navigate to a different page using NavigationManager.
This works all fine.
However when I quickly click "Page1","Page2", or any other combination of 2 or more pages I have a problem that my Page1 loads but directly another Page is loaded because I quickly clicked menu items.
My pages contain async/await methods and here I have the problem for example:
- quickly click "Page3", click "Page1", click "Page2"
- Navigation occurs to "Page3"
- async methods in Page3 kick in (using async/await/events attached/...)
- Suddenly navigation occurs to "Page1"
- Blazor app crashed because for example an async task returned data or accesses a component from "Page3", which has been disposed already because we navigate to "Page1"
- If we are lucky we reached "Page1", but same might happen because a navigation to "Page2" occurs directly
When a navigation occurs, is there a way to "cancel" the current page when navigating to a different page? (E.g. maybe something similar to a CancellationToken ?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Blazor应用不应该崩溃。所有页面都是由
Renderer
管理其生命周期的组件。在完成渲染之前,可以将它们从渲染中删除,但是渲染器仍将等待其事件周期的完成,然后再提及它们:他们将完成活动周期。这是一个演示计数器,供您快速单击Thro并查看会发生什么。当从渲染树中删除组件时,处置被调用,但是
生命周期仍然完成。
The Blazor App shouldn't crash. All the pages are components whose lifecycle is managed by the
Renderer
. They may be removed from the RenderTree before they have completed rendering, but the Renderer will still await the completion of their event cycle before dropping it's reference to them: they will complete their event cycle.Here's a demo counter for you to quickly click thro and see what happens. Dispose gets called when the component in removed from the RenderTree, but the
lifecycle still completes.