You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Maui路由查找失败:调用GoToAsync报错如何解决?

Shell路由无法找到"//PortfolioSummary"的错误分析与解决

错误原因

  • Shell的//前缀用于定位根级路由节点,但你当前的PortfolioSummary路由是定义在FlyoutItem的子节点ShellContent上,而FlyoutItem本身未设置Route属性,根节点下不存在直接匹配的路由项。
  • 如果绑定的ShowUserMenuItems值为false,FlyoutItem会被隐藏,对应的ShellContent路由不会被Shell注册,也会触发该错误。

解决方法

方法1:给FlyoutItem添加路由,通过层级路径访问

修改XAML代码,为FlyoutItem设置根级路由:

<FlyoutItem Title="Portfolio Summary" IsVisible="{Binding ShowUserMenuItems}" Route="PortfolioGroup">
    <ShellContent ContentTemplate="{DataTemplate views:PortfolioSummaryPage}" Route="PortfolioSummary"/>
</FlyoutItem>

调用路由时使用层级路径:

await Shell.Current.GoToAsync("//PortfolioGroup/PortfolioSummary");

方法2:将路由直接设置在FlyoutItem上(适用于单个ShellContent的场景)

如果该FlyoutItem仅包含一个ShellContent,可以直接把路由移到FlyoutItem上:

<FlyoutItem Title="Portfolio Summary" IsVisible="{Binding ShowUserMenuItems}" Route="PortfolioSummary">
    <ShellContent ContentTemplate="{DataTemplate views:PortfolioSummaryPage}"/>
</FlyoutItem>

此时原路由调用代码可以正常使用:

await Shell.Current.GoToAsync("//PortfolioSummary");

额外检查

确认绑定的ShowUserMenuItems值为true,确保FlyoutItem处于可见状态,Shell才能注册其包含的路由。

内容的提问来源于stack exchange,提问作者Karl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 22:44:54