简体   繁体   English

Blazor 未在子文件夹中发现新页面

[英]Blazor not discovering new pages in subfolders

I create a new page, eg in Pages/Clients/ subfolder with following code:我创建一个新页面,例如在 Pages/Clients/ 子文件夹中使用以下代码:

@page "/clients"
@inject NavigationManager NavigationManager
<div>My clients page</div>

I put the link:我放了链接:

<NavLink href="/clients" class="nav-link">Clients</NavLink>

When I click on link the page shows me default message当我点击链接时,页面会显示我的默认消息

Sorry, there's nothing at this address.抱歉,此地址没有任何内容。

Then I stop the app.然后我停止应用程序。 Put my clients page in "Pages" folder.将我的客户页面放在“页面”文件夹中。 Run the application and I see the proper page with运行应用程序,我看到正确的页面

My clients page我的客户页面

Ok, then I move my page file again to Pages/Clients/ subfolder, run the app and... it still works!好的,然后我再次将我的页面文件移动到 Pages/Clients/ 子文件夹,运行应用程序......它仍然有效! Moreover - If I do any changes to Clients.razor page it is being shown correctly in browser.此外 - 如果我对 Clients.razor 页面进行任何更改,它会在浏览器中正确显示。

So it looks like Blazor cannot find the page in subfolder for the first time, but after it "registers" it somehow it could find and show it correctly all the time.因此,Blazor 似乎第一次无法在子文件夹中找到该页面,但是在它“注册”之后,它可以以某种方式始终正确地找到并显示它。

I have the我有

<base href="~/" />

line in my _Host.cshtml file我的 _Host.cshtml 文件中的一行

Well, I was fighting with it for a couple of days and right after posting on Stackoverflow I accidentally found an answer.好吧,我与它斗争了几天,在 Stackoverflow 上发帖后,我意外地找到了答案。 In your .csproj file there were following lines:在您的 .csproj 文件中有以下几行:

  <ItemGroup>
    <Watch Include="**\*.razor" />
  </ItemGroup>

  <ItemGroup>
    <Content Remove="Pages\Activities\ActivitiesList.razor" />
    <Content Remove="Pages\Entrance\Entrance.razor" />
    <Content Remove="Pages\Instructors\InstructorsList.razor" />
    <Content Remove="Pages\Plan\Plan.razor" />
  </ItemGroup>

  <ItemGroup>
    <None Include="Pages\Activities\ActivitiesList.razor" />
    <None Include="Pages\Administration\Administration.razor" />
    <None Include="Pages\Entrance\Entrance.razor" />
    <None Include="Pages\Instructors\InstructorsList.razor" />
    <None Include="Pages\Plan\Plan.razor" />
  </ItemGroup>

  <ItemGroup>
    <Watch Remove="Pages\Activities\ActivitiesList.razor" />
    <Watch Remove="Pages\Administration\Administration.razor" />
    <Watch Remove="Pages\Entrance\Entrance.razor" />
    <Watch Remove="Pages\Instructors\InstructorsList.razor" />
    <Watch Remove="Pages\Plan\Plan.razor" />
  </ItemGroup>

I removed most of them and left only this:我删除了其中的大部分,只留下了这个:

  <ItemGroup>
    <Watch Include="**\*.razor" />
  </ItemGroup>

All the files are being now discovered correctly.现在可以正确发现所有文件。 Just remember to check your csproj if some garbage aren't being generated there during development process.如果在开发过程中没有在那里生成一些垃圾,请记住检查您的 csproj。

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

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