[英]Visual Studio Community 2019 16.5.3 with Blazor App -> Add -> New Item -> Razor Component -> Route or component is not rendered
I have a very weird problem.我有一个非常奇怪的问题。
I'm following the official Blazor tutorial from Microsoft:我正在关注微软的官方 Blazor 教程:
Add a new Todo Razor component to the app in the Pages folder.
在 Pages 文件夹中的应用程序中添加一个新的 Todo Razor 组件。 In Visual Studio, right-click the Pages folder and select Add > New Item > Razor Component.
在 Visual Studio 中,右键单击 Pages 文件夹和 select 添加 > 新项目 > Razor 组件。 Name the component's file Todo.razor.
将组件的文件命名为 Todo.razor。 In other development environments, add a blank file to the Pages folder named Todo.razor.
在其他开发环境中,将一个空白文件添加到名为 Todo.razor 的 Pages 文件夹中。
https://docs.microsoft.com/en-us/aspnet/core/tutorials/build-your-first-blazor-app?view=aspnetcore-3.1#build-a-todo-list https://docs.microsoft.com/en-us/aspnet/core/tutorials/build-your-first-blazor-app?view=aspnetcore-3.1#build-a-todo-list
Done like this:这样做:
This creates a file that looks like this:这将创建一个如下所示的文件:
<h3>Todo</h3>
@code {
}
Given that it has no routing I add @page "/todo"
to the top, exactly like the example pages Counter.razor
and FetchData.razor
has.鉴于它没有路由,我将
@page "/todo"
添加到顶部,就像示例页面Counter.razor
和FetchData.razor
。
I then start the application but I can't navigate to然后我启动应用程序,但我无法导航到
I have tried renaming the route to different names, check the folder for any scrap files, created new files but there is nothing that I can find.我尝试将路线重命名为不同的名称,检查文件夹中是否有任何废品文件,创建新文件,但我找不到任何东西。
No matter what I do the not found is hit from App.razor
.无论我做什么,都找不到
App.razor
。
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Now to the really weird part.现在到了真正奇怪的部分。 If I copy the file Counter.razor and rename
@page
to whatever I want it will work.如果我复制文件 Counter.razor 并将
@page
重命名为我想要的任何内容,它将起作用。
I then suspected this had something to do with encoding or hidden chars etc. But If I copy the entire working file content and only change @page
it will still not work if the file was created from the UI.然后我怀疑这与编码或隐藏字符等有关。但是如果我复制整个工作文件内容并且只更改
@page
如果文件是从 UI 创建的,它仍然无法工作。 What could be the cause of this?这可能是什么原因?
I have not modified anything else, everything done is simply add a new Blazor App -> Blazor Server App with Individual User Accounts -> Connect to an existing user store in the cloud (Azure AD B2C).我没有修改任何其他内容,所做的一切只是添加一个新的 Blazor 应用程序 -> 带有个人用户帐户的 Blazor 服务器应用程序 -> 连接到云中的现有用户存储(Azure AD B2C)。
I can not add it as a component either.我也不能将它添加为组件。 Adding
<Todo2 />
to Index.razor
will show up but <Todo />
will be blank.将
<Todo2 />
添加到Index.razor
将显示,但<Todo />
将为空白。
What could be the cause of this?这可能是什么原因?
Turned out to be a .csproj
issue.原来是一个
.csproj
问题。 The following values were present:存在以下值:
<ItemGroup>
<Watch Remove="Pages\Todo.razor" />
<Watch Remove="Pages\Todo2.razor" />
</ItemGroup>
<ItemGroup>
<None Include="Pages\Todo.razor" />
</ItemGroup>
After deleting every ItemGroup
it started working again since the files are watched by default.删除每个
ItemGroup
后,它再次开始工作,因为默认情况下会监视文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.