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

Blazor客户端项目Pages文件夹添加子文件夹后路由访问异常问题

Fixing Blazor Navigation Issue for TimeLogs/Log.razor

Hey there, let's get that navigation working for your Time Log page. The problem is a simple mismatch between your NavLink target and the route defined in your Log.razor component—here's how to fix it step by step:

1. Update the Route in Log.razor

Your Log.razor sits in the Pages/TimeLogs subfolder, so aligning the component's route with this structure keeps your project organized and intuitive. Change the @page directive from /log to /timelogs/log:

@page "/timelogs/log"
@using Nessie.Shared
@inject HttpClient Http

<h1>put info here</h1>
the data can be inserted here

@code { }

Your current NavLink points to TimeLog/log, which doesn't match the route we just set. Update the href value to match the component's new route. Using an absolute path (starting with /) ensures it works no matter where the NavMenu is rendered:

<li class="nav-item px-3">
    <NavLink class="nav-link" href="/timelogs/log">
        <span class="oi oi-list-rich" aria-hidden="true"></span> Time Log
    </NavLink>
</li>

Quick Explanation

Blazor relies entirely on the @page directive to map URLs to components—the folder structure doesn't automatically define routes. In your original setup, the NavLink tried to navigate to TimeLog/log, but your component was only registered for the /log route. By aligning both values, Blazor can now find and render the correct page when the link is clicked.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:46:33